Is the list of Java types ambiguous?

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

I want to find out how a simple web crawler is built, and I use 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

Source provided by website: http://java.sun.com/developer/technicalArticles/ThirdParty/WebCrawler/WebCrawler.java

I am running eclipse 3.2 and using the Java-Java-6 JRE to compile applets. I work for Crunchbang, the Ubuntu distribution.

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

List listmatches; 

The error says " The type List is ambiguous ".

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

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

+6
source share
3 answers

Add import java.awt.List; into your import statements. Then it will work well.

This is mainly because there is java.util.List and a java.awt.List . Since you import both of them using wildcards, the compiler does not know which one you really want.

+5
source

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

To solve this problem, you should choose one of them, which is most likely used in the application (I would suggest java.awt.List.

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

+1
source

To avoid such an ambiguous message, we need to import either "java.util.List" or "java.awt.List", in particular, based on your needs. If you use both, then there is such confusion. To see an example program, use http://www.cjavaprogramsprojects.com/java-final-year-mini-project-file-loader

0
source

Source: https://habr.com/ru/post/888453/


All Articles