Java 类型列表不明确?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6048946/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 14:07:37  来源:igfitidea点击:

Java type list is ambiguous?

javalist

提问by inquirydroid

I am a programming enthusiast with a basic programming background, but I'm completely new to the Java programming language.

我是一个具有基本编程背景的编程爱好者,但我对 Java 编程语言完全陌生。

I want to learn how a simple web crawler is built and I'm using this site to compile the source to see how it works and see it in action! http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/#demo

我想了解一个简单的网络爬虫是如何构建的,我正在使用这个站点来编译源代码以查看它是如何工作的并查看它的运行情况! http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/#demo

The source provided by the website is here: http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/WebCrawler.java

网站提供的源码在这里:http: //java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/WebCrawler.java

I am running eclipse 3.2 and using the sun-java-6 JRE to compile applets. I am running on Crunchbang, a Ubuntu distro.

我正在运行 eclipse 3.2 并使用 sun-java-6 JRE 来编译小程序。我在 Ubuntu 发行版 Crunchbang 上运行。

There is some part of the library that I am unfamiliar with and do not know how to fix.

图书馆的某些部分我不熟悉,不知道如何解决。

List listmatches;

The error says that "The type List is ambiguous".

错误说“ The type List is ambiguous”。

I have the package java.utils.*;but the error still persist.

我有包裹,java.utils.*;但错误仍然存​​在。

Is there something wrong with my syntax or is there a new syntax for List?

我的语法有问题还是有新的语法List

采纳答案by Thomas Jungblut

Add import java.awt.List;to your import statements. This should work fine then.

添加import java.awt.List;到您的导入语句。这应该可以正常工作。

This is mainly because there is a java.util.Listand a java.awt.List. Since you are importing both of them using wildcards, the compiler doesn't know which one you actually want to.

这主要是因为有 ajava.util.List和 a java.awt.List。由于您使用通配符导入它们,编译器不知道您真正想要哪个。

回答by amischiefr

The reason that you get the "ambiguous" message is because there is a List class in both "java.awt." and the "java.util." packages that are at the top of the import list.

您收到“模棱两可”消息的原因是,在导入列表顶部的“java.awt. ”和“java.util.”包中都有一个 List 类。

To solve this issue you should pick one of them that most likely is being used in the application (I would guess java.awt.List.

要解决此问题,您应该选择最有可能在应用程序中使用的其中一个(我猜是 java.awt.List。

In eclipse if you do a "CTRL + SHIFT + o" (that's an o not a zero), it will refactor your imports. From there you can select the java.awt.List.

在 Eclipse 中,如果您执行“CTRL + SHIFT + o”(即 o 而不是零),它将重构您的导入。从那里您可以选择 java.awt.List。

回答by Revathy Parirajan

To avoid such ambiguous message, we have to import either "java.util.List" or "java.awt.List" specifically based on your need. If you use both, then the confusion may arise such problem. To see example program using this, please visit http://www.cjavaprogramsprojects.com/java-final-year-mini-project-file-loader

为了避免这种含糊不清的消息,我们必须根据您的需要专门导入“java.util.List”或“java.awt.List”。如果两者都使用,那么可能会出现这样的混淆问题。要查看使用它的示例程序,请访问http://www.cjavaprogramsprojects.com/java-final-year-mini-project-file-loader