Community
Participate
Working Groups
I'm still having some problems fully grasping generics, so I apologize if this is a red-herring. java.util.Collection defines: <T> T[] toArray(T[] a); Should public Object[] toArray(Object[] a) be a valid signature for an implementation of toArray? Currently, it isn't be recognized as such -- it's not marked as an error, but there is an error reported against the class: "Class must implement the inherited abstract method Collection.toArray(T[])" Tx. :-) (Eclipse I20040413, Cheetah03)
This isn't yet supported. We are working on it.
We now know which bridge methods we need... just need to generated them in the .classfile.
Code gen released. Also tweaked the code detecting the need for bridge methods, so as to only request them when signature erasure is different.
Reopening. Something is still wrong: import java.util.Collection; public abstract class X implements Collection<Object> { public Object[] toArray(Object[] a) { return a; } } ---------- 1. ERROR in d:\X.java (at line 5) public Object[] toArray(Object[] a) { ^^^^^^^^^^^^^^^^^^^ The return type is incompatible with Collection<Object>.toArray(T[]) ---------- 1 problem (1 error)
Javac does also reject the program for a more obvious reason: javac X.java -d ..\bin -source 1.5 -Xlint X.java:3: name clash: toArray(java.lang.Object[]) in X and <T>toArray(T[]) in java.util.Collection<java.lang.Object> have the same erasure, yet neither overrides the other public abstract class X implements Collection<Object> { ^ 1 error
That's deeply amusing. :-)
Closing as fixed. We reject the code as expected, but should improve error message a bit (TODO added).
What a sec, does that mean that Object[] toArray(Object[]) isn't a correct implementation of <T> T[] toArray(T[]) ? Are you *sure*? (I only ask because I've been looking into it, and, as far as I can tell, it is.)