dbf
dbf

Reputation: 415

The type Collection is not generic; it cannot be parameterized with arguments <? extends E>

I have a strange problem with Eclipse Galileo.
I set Java 1.6 as my JRE. On this line of code

List templates = new ArrayList ();

I see the following error in Eclipse's problem list:

The type Collection is not generic; it cannot be parameterized with arguments

I don't have any problems with building this project with Ant.
How can I fix it? Looks like it is an Eclipse problem, but because of this error, I can't compile/publish my project from the IDE.

Upvotes: 20

Views: 72167

Answers (13)

upog
upog

Reputation: 5521

I changed the import

   import javax.swing.text.html.HTMLDocument.Iterator;

to

   import java.util.Iterator;

then it worked for me

Upvotes: 1

Kadiri
Kadiri

Reputation: 308

Try to remove import antlr.collections.List; and click Ctr+space to use java.util

Upvotes: 0

Swagatika
Swagatika

Reputation: 3436

It's late but still replying, might be helpful for others who are still facing the issue. I was getting exactly the same issue. The List was proper with util.List. The solution was to order the exports of the libraries. If you are using Maven or any other Libraries :

In Project -> Build Path -> Configure Build Path -> Order & Exports

Check 'JRE System Libraries' should be above 'Maven Dependencies'

This worked for me.

Upvotes: 21

zen0n
zen0n

Reputation: 347

for example:

public class AClass<T extends Object>
{
 public HashMap<String, String> myMap;
}

if I write:

public class BClass
{

private AClass aClass = new AClass();

public void test()
{

aClass.get("test");
//return Object class

}

}

but if I write:

public class BClass
{

private AClass<?,?> aClass = new AClass<?,?>();

public void test()
{

aClass.get("test");
//return String class

}

}

Upvotes: 1

xxxx
xxxx

Reputation: 11

use "import java.util.List"

instead of default import "import antlr.collections.List;"

and use the JRE5 or above for generic support of collection API....

Upvotes: 1

Preston Cummings
Preston Cummings

Reputation: 31

Did you name your class list? i.e:

import java.util.*;

public class List {   // can't do this, name this something else.

    public static void main(String[] args) {
        List<Integer> l = new ArrayList<Integer>();

    }

}

Upvotes: 3

Sankar R.K
Sankar R.K

Reputation: 77

make java buildpath reference to greater than or equal to java 1.5

or you try to add the "import java.util.List" statement then you can see that

eclipse is saying it is conflicting with some other List type

for example it may be conflicting with com.lowagie.xx.xxx.List etc try to avoid these import

statements

Upvotes: 0

Camilo Cuesta
Camilo Cuesta

Reputation: 21

Hey, I removed the cryptic library and it didn't work. But then I put JRE System Library at the top, and it worked. Really weird.

Upvotes: 2

dbf
dbf

Reputation: 415

For those, who will get there from Google: the problem was with cryptix library. When I removed it from java build path the project is compiled sucesfully.

Upvotes: 6

Fabio
Fabio

Reputation: 11

put the entry "JRE System Library..." at the top in project, properties, java build path, order and export

Upvotes: 1

user85421
user85421

Reputation: 29680

Some ideas:

  • check the JRE library being used in your project (check the package explorer).
  • check the installed JREs in the eclipse settings (same as used by ant).
  • comment out the line just to check if it really is the error cause.
  • retype the whole line from scratch.
  • install a new (clean) version of eclipse, in a new folder (testing).

Upvotes: 0

Andreas Dolk
Andreas Dolk

Reputation: 114767

Sometimes it's an eclipse hiccup and eclipse -clean plus refreshing all projects helps.

Edit

Does it change anything when you replace your code with:

java.util.List templates = new java.util.ArrayList();

or even

java.util.List<Object> templates = new java.util.ArrayList<Object>();

?

Upvotes: 1

VonC
VonC

Reputation: 1323553

What List are you importing? (see this thread from 2006)

java.awt.List or java.util.List?

Because, as eclipse aptly comments, java.awt.List is not parameterized ;)


Check also the

  • Java Build path: it must not contain a reference to the J2SE 1.4.2 libraries.
  • Source Compatibility: project properties -> Java Compiler Settings, Source Compatibility 5.0 or 6.0.

Other than that, there was lots of issue back in 2005 when the latest Eclipse 3.1 beta was supporting J2SE5, but this was fixed since then.

Try tyo use the latest JDK6 in your project.

Upvotes: 38

Related Questions