First, it should be noted that the exact signature of the method that is supposed to be implemented:
<T> T[] toArray(T[] a);
And both javac and Eclipse warn you about this type safety issue. And if you change the signature to the expected one, javac will be happy.
If you put @Override in the toArray method, even with a signature using the raw Object type, both Eclipse and javac correctly interpret this as an override of the method declared by Collection . So there is no such problem.
Inconsistency, and I think the javac error is any implementation of the subclass, javac does not recognize the super method Object[] toArray(Object[] o) for implementing <T> T[] toArray(T[] a) . If this were to be done for an abstract class, I must also do this for each subclass.
This is not the first time javac has an error about this. See this thread . I searched the Oracle database, I did not report anything about what you found.
Then there is work around: in the abstrcat class, use the expected signature; Or override "manually" in subclasses:
public Object[] toArray(Object[] o) { return super.toArray(o); }
Nicolas LalevΓ©e
source share