• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error compiling generics  RSS feed

 
Marco Antonio Reis
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everybody!
I need some help in this advanced topic.
I wrote the following code at Eclipse and doesn't show me any problem, so I can run the teste without problems.
But when I try to compile the classes using JDK (command line or ant) I have the following error:
Test.java:9: incompatible types
found : java.util.Iterator<Person>
required: java.util.Iterator<IPerson>
return generaliza(iter);

The classes:
import java.util.*;
public class Test {
public <T, S extends T> Iterator<T> generaliza(Iterator<S> iter) {
return null;
}
public Iterator Iterator<IPerson> test (Iterator<Person> iter) {
return generaliza(iter);
}
}

public interface IPerson {
public String getName();
}

public class Person implements IPerson {
private String name;
public String getName() { return name;}
public void setName(String name) {this.name = name;}
}

The code works at Eclipse, but I have that error compiling in command line.
Do you know what happened!?!?!?!?!
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think eclipse is compiling this line without error:

a) Are you sure you're compiling the same source? Insert a serious syntax-error, to prove your assumption (recompile it in both styles).

b) Are you sure you're using the same java-compiler?
Control the settings in eclipse, and call 'which javac' on the commandline.

c) Please use code-tags in future, and use cut'n'paste to show exactly the code which isn't working.
[ April 10, 2006: Message edited by: Stefan Wagner ]
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a correction to the last post. (I'm on Windows XP Pro SP2).

1- Eclipse 3.1.2 does compile the code WITHOUT any error.
Of course this code is under a project that uses 5.0 compliance level.
By the way Eclipse uses it's OWN java compiler.

2- Sun's javac.exe 1.5.0_06 try to compile the same code WITH ERROR:
Test.java:7: incompatible types
found : java.util.Iterator<Person>
required: java.util.Iterator<IPerson>
return generaliza(iter);
^
1 error

I did some research in the Sun Java Bug database but without any success.
Is this a Sun's javac.exe bug?
The question remains (I don't know the answer):

*** What is the correct behaviour? ***

By the way this following test compiles fine with BOTH compilers:

So at first glance since there is no error in this case it *seems* that there should be no error also when parametrized types are "wrapped" by a class (java.util.Iterator in this case).
So my guess would be that it's a Sun's javac.exe bug.

Regards
 
Rodrigo Alvarez
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

By the way Eclipse uses it's OWN java compiler.


No it doesn't : it uses whatever JRE is defined in :
Window->Preferences->Java->Installed JRE's

=> I would suggest that you add there the javac.exe you're using on the command line , then select it as the JRE of your current project.

Cheers
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
quote: By the way Eclipse uses it's OWN java compiler.

No it doesn't : it uses whatever JRE is defined in :
Window->Preferences->Java->Installed JRE's


Simon,

You're mixing things here.
Eclipse uses its own incremental java compiler which is embedded in the JDT Core component.

The JRE is a different thing. It's the Java Runtime.
You can choose to add/remove many JREs if you will.
Also you can have different JRE for different projects.
Buy this is NOT the java compiler.

Regards
 
Rodrigo Alvarez
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jean-Francois Briere,

oups, sorry, looks like I mixed JRE and JDK.

Thks for the info

Simon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!