Bug 58903 - [1.5] Implementing inherited generic methods
Summary: [1.5] Implementing inherited generic methods
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-16 14:31 EDT by Marco Qualizza CLA
Modified: 2005-01-11 11:01 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Qualizza CLA 2004-04-16 14:31:44 EDT
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)
Comment 1 Philipe Mulet CLA 2004-04-16 19:16:59 EDT
This isn't yet supported. We are working on it.
Comment 2 Kent Johnson CLA 2004-04-19 15:13:38 EDT
We now know which bridge methods we need... just need to generated them in 
the .classfile.
Comment 3 Philipe Mulet CLA 2004-04-26 09:21:11 EDT
Code gen released. Also tweaked the code detecting the need for bridge methods, 
so as to only request them when signature erasure is different.
Comment 4 Philipe Mulet CLA 2004-04-26 09:27:54 EDT
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)
Comment 5 Philipe Mulet CLA 2004-04-26 09:43:28 EDT
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
Comment 6 Marco Qualizza CLA 2004-04-26 09:49:43 EDT
That's deeply amusing. :-)
Comment 7 Philipe Mulet CLA 2004-04-26 09:57:00 EDT
Closing as fixed. We reject the code as expected, but should improve error 
message a bit (TODO added).
Comment 8 Marco Qualizza CLA 2004-04-26 10:14:28 EDT
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.)