Community
Participate
Working Groups
The following generics construct is valid (and compiles) in 1.5 but Eclipse reports as a type mismatch: cannot convert Object[] to String[] MyGeneric<String> myGeneric = new MyGeneric<String>; String[] test = myGeneric.getElements (); Where MyGeneric declares, of course: public class MyGeneric<E> { ... public E[] getElements () { return elements; } ... }
Cannot reproduce in latest, given following test case: public class X<E> { public static void main(String[] args) { X<String> xs = new X<String>(); String[] test = xs.getElements (); } public E[] getElements () { return null; } } There is no instance of Object[] in your example, unclear where it comes from. Please reopen if you can still reproduce with latest, and if so, please provide more detailed steps to reproduce.
I'm running build 200412162000, or M4. As for "Object" (java.lang.Object), I don't declare anything to be of type Object. The compiler is the one that thinks, somehow, that the right hand side of this call will return Object[] (which it reports as incompatible with String[], as the message suggests): String[] test = myGeneric.getElements (); I'll have to wait for the next milestone, then, I gues... Zorzella
Does my example from comment#1 reproduces the problem for you ? It did not for me, even on plain M4 build. I suspect there is an issue, but I may not have reproduced it. Please try to reproduce it using my steps. BTW, are the 2 types involved here in separate files ? Does a full rebuild make the problem go away ? Reopening
Oh! You guessed right -- your example per se compiles, but if you simply split the main method to another file (not simply another private class!) it stops working. I don't think it's any refreshing, btw. Zorzella
Then this is a dup *** This bug has been marked as a duplicate of 81719 ***