Bug 79562 - Generics and Covariant Return
Summary: Generics and Covariant Return
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-26 10:46 EST by CW Renniks CLA
Modified: 2004-12-14 11:28 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 CW Renniks CLA 2004-11-26 10:46:41 EST
Hello,

I'm currently using 3.1m3 and am curious 
on why the following code builds fine within the IDE ( making sure the 
project is using the 1.5 ( 5 ) compiler ), but does NOT build fine when 
using the 1.5 javac.exe. Here's the code:

A.java
=====
public class A
{
}

B.java
=====
public class B extends A
{
}

C.java
======
import java.util.List;
public interface C
{
    List< A > getIt();
}

D.java
======
import java.util.List;
public interface D extends C
{
    List< B > getIt();
}

When building these files from the command line, I get the following error:

******************************************************************
F:\temp>javac *.java
D.java:4: getIt() in D clashes with getIt() in C; attempting to use 
incompatible return type
found   : java.util.List<B>
required: java.util.List<A>
   List< B > getIt();
             ^
1 error
*******************************************************************

But when I build those same files in the Eclipse 3.1m3 IDE, builds fine. I 
believe this code should NOT build. In order to make it build from the 
command line, I have to change C.java so that the getIt() method's return 
type looks like this:

List< ? extends A >

Regards,

Cameron
Comment 1 Philipe Mulet CLA 2004-11-26 11:22:24 EST
The "why" is simple: Eclipse defines its own Java compiler.

Now you may have found a bug...
Comment 2 Kent Johnson CLA 2004-11-26 11:36:08 EST
This was fixed last week.
Comment 3 Olivier Thomann CLA 2004-12-14 11:28:21 EST
Verified in 200412140800