Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Generics and compiler Difference Eclipse vs javac
Generics and compiler Difference Eclipse vs javac [message #257143] Sun, 02 November 2008 08:39 Go to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I just discover something strange when trying to build one of my
projects with maven.

I have code like this:

-------->8--------
public BaseClass {
private String propertyA = "";

public <V extends Object> V getProperty(int propertyId) {
if( propertyId == 1 ) {
return (V) propertyA;
}
throw new IllegalArgumentException(
"Property with id '"+propertyId+"' unknown.");
}
}

public MyClass extends BaseClass {
private String propertyB = "";

@Override
public <V extends Object> V getProperty(int ) {
if( propertyId == 2 ) {
return (V) propertyB;
}
return super.getProperty(propertyId);
}
}
-------->8--------

This compiles fine in Eclipse but compiling with javac I get the
following error.

-------->8--------
type parameters of <V>V cannot be determined; no unique maximal instance
exists for type variable V with upper bounds V,java.lang.Object.
-------->8--------

To make it compile I had to change it like this:

-------->8--------
public MyClass extends BaseClass {
private String propertyB = "";

@Override
public <V extends Object> V getProperty(int ) {
if( propertyId == 2 ) {
return (V) propertyB;
}
return (V) super.getProperty(propertyId);
}
}
-------->8--------

So it looks like the Eclipse Java Compiler is smarter than Javac but is
this really desired?

The javac I'm using is the one coming with OS-X 10.4 which is currently
javac 1.5.0_16.

Tom

--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Generics and compiler Difference Eclipse vs javac [message #257154 is a reply to message #257143] Mon, 03 November 2008 09:00 Go to previous message
Eclipse UserFriend
Originally posted by: mauro.molinari.cardinis.com

Tom Schindl ha scritto:
> So it looks like the Eclipse Java Compiler is smarter than Javac but is
> this really desired?

If it were, it would not be the first case...

Try to have a look in Eclipse and/or Sun bug trackers: if there's a bug
report against javac already open, I think Eclipse Java Compiler is ok
and doesn't need to be changed. If there is not, I know about other
times in which EJC has been changed in order to be compatible with
javac, even if this went against the Java Language Specification.

Anyway, a JDT developer would certainly give you a better answer.

Mauro.
Previous Topic:the templates weren't work for me
Next Topic:How can I view Java bytecode in eclipse?
Goto Forum:
  


Current Time: Fri Aug 16 15:26:54 GMT 2024

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

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

Back to the top