简体   繁体   English

Collection类型不是通用的;它不能用参数<?参数化延伸E>

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

I have a strange problem with Eclipse Galileo. 我对Eclipse Galileo有一个奇怪的问题。
I set Java 1.6 as my JRE. 我将Java 1.6设置为我的JRE。 On this line of code 在这行代码上

List templates = new ArrayList ();

I see the following error in Eclipse's problem list: 我在Eclipse的问题列表中看到以下错误:

The type Collection is not generic; Collection类型不是通用的; it cannot be parameterized with arguments 它不能用参数参数化

I don't have any problems with building this project with Ant. 使用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. 看起来这是一个Eclipse问题,但由于这个错误,我无法从IDE编译/发布我的项目。

What List are you importing? 您要导入什么List (see this thread from 2006 ) (参见2006年的这篇帖子

java.awt.List or java.util.List ? java.awt.List还是java.util.List

Because, as eclipse aptly comments, java.awt.List is not parameterized ;) 因为,正如eclipse恰当地评论, java.awt.List没有参数化;)


Check also the 检查一下

  • Java Build path : it must not contain a reference to the J2SE 1.4.2 libraries. Java构建路径 :它不能包含对J2SE 1.4.2库的引用。
  • Source Compatibility : project properties -> Java Compiler Settings, Source Compatibility 5.0 or 6.0. 源兼容性 :项目属性 - > Java编译器设置,源兼容性5.0或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. 除此之外,2005年最新的Eclipse 3.1测试版支持J2SE5时出现了很多问题,但从那时起就修复了。

Try tyo use the latest JDK6 in your project. 尝试使用项目中最新的JDK6。

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. 列表适用于util.List。 The solution was to order the exports of the libraries. 解决方案是订购库的导出。 If you are using Maven or any other Libraries : 如果您使用Maven或任何其他库:

In Project -> Build Path -> Configure Build Path -> Order & Exports 在项目 - >构建路径 - >配置构建路径 - >订单和导出

Check 'JRE System Libraries' should be above 'Maven Dependencies' 检查'JRE系统库'应该高于'Maven依赖关系'

This worked for me. 这对我有用。

For those, who will get there from Google: the problem was with cryptix library. 对于那些将从谷歌到达那里的人:问题在于cryptix库。 When I removed it from java build path the project is compiled sucesfully. 当我从java构建路径中删除它时,该项目是成功编译的。

Did you name your class list? 你有没有列出你的班级名单? ie: 即:

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>();

    }

}

Hey, I removed the cryptic library and it didn't work. 嘿,我删除了神秘的图书馆,它没有用。 But then I put JRE System Library at the top, and it worked. 但后来我把JRE系统库放在了最顶端,它起作用了。 Really weird. 真的很奇怪。

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

}

}

Sometimes it's an eclipse hiccup and eclipse -clean plus refreshing all projects helps. 有时这是一个日食打嗝和eclipse -clean加上令所有项目更新的帮助。

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>();

?

将条目“JRE System Library ...”放在项目,属性,java构建路径,顺序和导出的顶部

I changed the import 我改变了导入

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

to

   import java.util.Iterator;

then it worked for me 然后它对我有用

use "import java.util.List" 使用“import java.util.List”

instead of default import "import antlr.collections.List;" 而不是默认导入“import antlr.collections.List;”

and use the JRE5 or above for generic support of collection API.... 并使用JRE5或更高版本来获取集合API的通用支持....

Try to remove import antlr.collections.List; 尝试删除import antlr.collections.List; and click Ctr + space to use java.util 并单击Ctr + space以使用java.util

Some ideas: 一些想法:

  • check the JRE library being used in your project (check the package explorer). 检查项目中使用的JRE库(检查包浏览器)。
  • check the installed JREs in the eclipse settings (same as used by ant). 在eclipse设置中检查已安装的JRE(与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). 在一个新文件夹(测试)中安装一个新的(干净的)eclipse版本。

make java buildpath reference to greater than or equal to java 1.5 使java buildpath引用大于或等于java 1.5

or you try to add the "import java.util.List" statement then you can see that 或者您尝试添加“import java.util.List”语句,然后您可以看到

eclipse is saying it is conflicting with some other List type eclipse说它与其他一些List类型相冲突

for example it may be conflicting with com.lowagie.xx.xxx.List etc try to avoid these import 例如,它可能与com.lowagie.xx.xxx.List等冲突,试图避免这些导入

statements 声明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ArrayList类型不是通用的。 不能使用参数对其进行参数化 - The type ArrayList is not generic; it cannot be parameterized with arguments Set类型不是通用的; 不能使用参数对其进行参数化 <K> - The type Set is not generic; it cannot be parameterized with arguments <K> ArrayList 类型不是通用的; 它不能用参数参数化<Integer> - The type ArrayList is not generic; it cannot be parameterized with arguments <Integer> 错误“kafkaconsumer 类型不是通用的,不能用参数参数化” - Error “the type kafkaconsumer is not generic it cannot be parameterized with arguments” Prevayler类型不是通用的。 不能使用参数对其进行参数化 <P> - The type Prevayler is not generic; it cannot be parameterized with arguments <P> 类型ConcurrentlinkedQueue不是通用的; 不能使用参数对其进行参数化 <Integer> - The type ConcurrentlinkedQueue is not generic; it cannot be parameterized with arguments <Integer> JComboBox类型不是通用的;它不能使用参数<Object>进行参数化 - The type JComboBox is not generic; it cannot be parameterized with arguments <Object> Iterator类型不是通用的; 不能使用参数对其进行参数化 <CustomTypeName> - The type Iterator is not generic; it cannot be parameterized with arguments <CustomTypeName> 队列类型不是通用的; 不能使用参数对其进行参数化 <Customer> - The type Queue is not generic; it cannot be parameterized with arguments <Customer> JList类型不是通用的; 不能使用参数对其进行参数化 <String> - The type JList is not generic; it cannot be parameterized with arguments <String>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM