Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » compiler bug with generic / return type override (disagree with sun javac)
compiler bug with generic / return type override (disagree with sun javac) [message #258638] Wed, 11 February 2009 20:56 Go to next message
Eclipse UserFriend
This code give no error with sun javac 1.5.0_17 and 1.6.0_12,
but error in eclipse 3.4 (org.eclipse.jdt.core_3.4.2.v_883_R34x.jar).
[ no, I didn't


----------
1. ERROR in ClassC.java (at line 1)
public class ClassC<T> extends ClassB<T> implements InterfaceA<T> {
^^^^^^
The return type is incompatible with InterfaceA<T>.get(T),
ClassB<T>.get(Object)
----------
1 problem (1 error)



========= source code =========
public interface InterfaceA<T> {
public int get(T o);
}
public class ClassB<T> {
T get(Object o) {
return null;
}
}
public class ClassC<T> extends ClassB<T> implements InterfaceA<T> {
public int get(T o) {
return 0;
}
}
Re: compiler bug with generic / return type override (disagree with sun javac) [message #258645 is a reply to message #258638] Thu, 12 February 2009 03:03 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauro.molinari.cardinis.com

CHENG Yuk Pong ha scritto:
> This code give no error with sun javac 1.5.0_17 and 1.6.0_12,
> but error in eclipse 3.4 (org.eclipse.jdt.core_3.4.2.v_883_R34x.jar).
> [ no, I didn't
>
> ----------
> 1. ERROR in ClassC.java (at line 1)
> public class ClassC<T> extends ClassB<T> implements InterfaceA<T> {
> ^^^^^^
> The return type is incompatible with InterfaceA<T>.get(T),
> ClassB<T>.get(Object)
> ----------
> 1 problem (1 error)
>
>
>
> ========= source code =========
> public interface InterfaceA<T> {
> public int get(T o);
> }
> public class ClassB<T> {
> T get(Object o) {
> return null;
> }
> }
> public class ClassC<T> extends ClassB<T> implements InterfaceA<T> {
> public int get(T o) {
> return 0;
> }
> }

I sounds very strange to me that javac doesn't give any error: the two
methods (get(T) in InterfaceA<T> and get(Object) in ClassB<T>) have the
same erasure, but different return type. I would be surprised if javac
would consider covariant the return type of get(Object) by wrappig int
to Integer after the erasure...

A JDT developer will surely give you a better answer.

Mauro.
Re: compiler bug with generic / return type override (disagree with sun javac) [message #258661 is a reply to message #258638] Thu, 12 February 2009 10:41 Go to previous messageGo to next message
Eclipse UserFriend
CHENG Yuk Pong a écrit :
> This code give no error with sun javac 1.5.0_17 and 1.6.0_12,
> but error in eclipse 3.4 (org.eclipse.jdt.core_3.4.2.v_883_R34x.jar).
> [ no, I didn't
This compiles fine with Eclipse 3.5M5 or 3.4.2 (build M20090204-1400).
So you should update your Eclipse install.
--
Olivier
Re: compiler bug with generic / return type override (disagree with sun javac) [message #258665 is a reply to message #258661] Thu, 12 February 2009 10:42 Go to previous messageGo to next message
Eclipse UserFriend
Olivier Thomann a écrit :
> This compiles fine with Eclipse 3.5M5 or 3.4.2 (build M20090204-1400).
> So you should update your Eclipse install.
I haven't tried 3.4.1. So maybe this has been fixed for 3.4.1.
--
Olivier
Re: compiler bug with generic / return type override (disagree with sun javac) [message #258682 is a reply to message #258661] Fri, 13 February 2009 06:17 Go to previous messageGo to next message
Eclipse UserFriend
Olivier Thomann wrote:

> CHENG Yuk Pong a écrit :
>> This code give no error with sun javac 1.5.0_17 and 1.6.0_12,
>> but error in eclipse 3.4 (org.eclipse.jdt.core_3.4.2.v_883_R34x.jar).
>> [ no, I didn't
> This compiles fine with Eclipse 3.5M5 or 3.4.2 (build M20090204-1400).
> So you should update your Eclipse install.

Thanks. 3.5M5 works.
(3.4.1 don't)
Re: compiler bug with generic / return type override (disagree with sun javac) [message #258686 is a reply to message #258661] Fri, 13 February 2009 06:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mauro.molinari.cardinis.com

Olivier Thomann ha scritto:
> CHENG Yuk Pong a écrit :
>> This code give no error with sun javac 1.5.0_17 and 1.6.0_12,
>> but error in eclipse 3.4 (org.eclipse.jdt.core_3.4.2.v_883_R34x.jar).
>> [ no, I didn't
> This compiles fine with Eclipse 3.5M5 or 3.4.2 (build M20090204-1400).
> So you should update your Eclipse install.
> --
> Olivier

Nice thing... however, quite absurd to me...

The following class does compile together with the other ones:

public class ClassE extends ClassC<Object>{
}

but the following one does not:

public class ClassE extends ClassC<Object>{

@Override
public int get (Object o) {
System.out.println ("get <= int");
return -1;
}
}

although I'm just trying to override ClassC.get(Object)...

So it seems that javac (and the latest versions of JDT) let me:
1) write a class for which I cannot override a method that I should be
able to override?
2) write a class with two methods having the same signature erasure?
3) what happens if I try to call get(<any object>) on an instance of
ClassE (if ClassE is defined as empty, so that it compiles)? Is
ClassB.get(Object) or ClassC(Object) called?

Just for my curiosity...

Mauro.
Re: compiler bug with generic / return type override (disagree with sun javac) [message #258697 is a reply to message #258686] Fri, 13 February 2009 13:45 Go to previous message
Eclipse UserFriend
"Mauro Molinari" <mauro.molinari@cardinis.com> wrote in message
news:gn3mav$f4$1@build.eclipse.org...
> So it seems that javac (and the latest versions of JDT) let me:
> 1) write a class for which I cannot override a method that I should be
> able to override?
> 2) write a class with two methods having the same signature erasure?
> 3) what happens if I try to call get(<any object>) on an instance of
> ClassE (if ClassE is defined as empty, so that it compiles)? Is
> ClassB.get(Object) or ClassC(Object) called?

I think
http://java.sun.com/docs/books/jls/third_edition/html/classe s.html#8.4.8.4
talks about this. In general it is okay to write inconsistent or
conflicting definitions (e.g. definitions that erase to the same thing in a
particular instance), the problem does not happen until they have to be
resolved. I think that for question 3, the calling code would not compile.
Previous Topic:Structural search (and replace)
Next Topic:unable to use eclipse 3.4.1 on mac os x
Goto Forum:
  


Current Time: Sat Apr 19 10:26:38 EDT 2025

Powered by FUDForum. Page generated in 0.03477 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top