| Covariant Return Types [message #250309] | 
Mon, 07 June 2004 18:56   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Originally posted by: robert.elliot.dial.pipex.com 
 
Hi all.  I've met an issue with Eclipse 3 M9 (and also as it happens 
WSAD5) which isn't really a bug as such.  Basically, I've written an API 
using Java 1.5 syntax, including covariant return types.  Having compiled 
it up using a 1.5 javac, I ran an excellent little utility called 
Retroweaver over it which transforms 1.5 byte code to make it 1.2, 1.3 and 
1.4 compatible.  Then jarred it up, and imported the jar into an Eclipse 
Java project; but Eclipse doesn't like it.  The API contains 2 classes 
effectively doing the following: 
 
// Initial class 
public abstract class Foo { 
protected Object foo() { 
return "Hi"; 
} 
} 
 
// Subclass that over-rides foo() with a covariant return type 
public abstract class FooExt extends Foo { 
protected String foo() { 
return (String) super.foo(); 
} 
} 
 
The intention of the API is that clients subclass FooExt to provide public 
methods.  So having brought the API jar into a Java 1.3 Eclipse project, I 
created a new java file subclassing FooExt as follows: 
 
public class Bar extends FooExt { 
public String getText() { 
return foo(); 
} 
} 
 
Now that will compile fine from the command line using a 1.3 javac with a 
-classpath pointing at my bytecode modified API jar, and the result will 
run fine on a 1.3 JVM.  However, both Eclipse & WSAD really don't like it 
because of the covariant return types; I get a red X by the first line of 
the class and doing mouse over displays the following error message: 
 
- The return type is incompatible with Foo.foo(), FooExt.foo() 
 
So my query is, do the Eclipse team think this is something worth "fixing" 
in Eclipse, since 1.3 compilers and JVMs are happy with it?  Or do they 
consider that this is a (useful!) bug in the 1.3 compilers and JVMs since 
they are not meant to support covariant return types, and so not something 
Eclipse should be worried about? 
 
Regards, 
Rob
 |  
 |  
  | 
 | 
Powered by 
FUDForum. Page generated in 0.06428 seconds