Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

A constructor is stuck with the first type it's called with. (ClassCastException) #486

Open
utybo opened this issue Jun 27, 2017 · 2 comments

Comments

@utybo
Copy link

utybo commented Jun 27, 2017

This title probably isn't clear enough, so here is the code that is problematic

function myFunction = {
  label("My label is awesome!")
  label(someIcon) # note : someIcon oftype javax.swing.Icon == true
}

function label = |textOrIcon| {
  return javax.swing.JLabel(textOrIcon)
}

The second use of label yields a ClassCastException : java.lang.ClassCastException: Cannot cast javax.swing.Icon to java.lang.String

If reversed (i.e we use label(someIcon) first), this also yields a ClassCastException, except that it's the other way around : java.lang.ClassCastException: Cannot cast java.lang.String to javax.swing.Icon

This shouldn't happen : the JLabel class has two constructors : JLabel(String) and JLabel(Icon). One would except Golo to be able to dynamically call either of the two depending on the object we give.

@yloiseau
Copy link
Contributor

yloiseau commented Jun 28, 2017

Probably a duplicate of #341 (see https://github.com/eclipse/golo-lang/projects/2)

@utybo
Copy link
Author

utybo commented Jun 28, 2017

Alright -- It probably is now that I think about it -- I wasn't sure so I preferred to open an issue with a concrete example.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants