在 Java 中导入 LinkedList 出现错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32912778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Importing LinkedList in Java giving an error
提问by Ritam Das
I have created a class called 'Function' and want to create a LinkedList in it. So I have written the following code (Cropped to the problem area only).
我创建了一个名为“Function”的类,并想在其中创建一个 LinkedList。所以我写了以下代码(仅裁剪到问题区域)。
import java.util.LinkedList;
import java.util.ArrayList;
class Function{
ArrayList<Integer> arrayList = new ArrayList<Integer>();
LinkedList<Integer> linkedList = new LinkedList<Integer>();
protected void addbeg(){
}
}
In the import LinkedList line, I am getting the following error: "The import java.util.LinkedList
conflicts with a type defined in the same file"
在导入 LinkedList 行中,我收到以下错误:“import java.util.LinkedList
与在同一文件中定义的类型冲突”
and In the line where I declaring a variable linkedList of type Linked list LinkedList<Integer> linkedlist = new LinkedList<Integer>()
, it is giving the follwoing error 'The type LinkedList is not generic; it cannot be parameterized with arguments '
并且在我声明 Linked list 类型的变量 linksList 的行中LinkedList<Integer> linkedlist = new LinkedList<Integer>()
,它给出了以下错误“类型 LinkedList 不是通用的;它不能用参数参数化 '
Any help how to eliminate these error? I have seen some tutorial on Java LinkedList where they have written same code without getting any error. I should also mention that The ArrayList is running without any error.
任何帮助如何消除这些错误?我看过一些关于 Java LinkedList 的教程,他们编写了相同的代码而没有出现任何错误。我还应该提到 ArrayList 正在运行,没有任何错误。
回答by T.J. Crowder
The import java.util.LinkedList conflicts with a type defined in the same file
导入 java.util.LinkedList 与同一文件中定义的类型冲突
The error is really quite specific, it's saying that somewhere in the file you have:
该错误确实非常具体,它表示您在文件中的某个地方:
class LinkedList {
}
...or possibly interface LinkedList
or enum LinkedList
, though that latter seems unlikely.
...或可能interface LinkedList
或enum LinkedList
,尽管后者似乎不太可能。
Remove or rename that, or remove the import
use the fully-qualified name when using java.util.LinkedList
(stronglyrecommend the former, not the latter).
删除或重命名,或删除import
使用时使用的完全限定名称java.util.LinkedList
(强烈推荐前者,而不是后者)。