JavaRanch » Java Forums »
Java »
Beginning Java
| Author |
reference to List(interface) is ambiguous
|
yuqing ma
Greenhorn
Joined: Nov 10, 2004
Posts: 11
|
|
code: //: c11:Collection1.java // Things you can do with all Collections. // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 // www.BruceEckel.com. See copyright notice in CopyRight.txt. import com.bruceeckel.simpletest.*; import java.util.*; import com.bruceeckel.util.*; public class Collection1 { private static Test monitor = new Test(); public static void main(String[] args) { Collection c = new ArrayList(); Collections2.fill(c, Collections2.countries, 5); c.add("ten"); c.add("eleven"); System.out.println(c); // Make an array from the List: Object[] array = c.toArray(); // Make a String array from the List: String[] str = (String[])c.toArray(new String[1]); // Find max and min elements; this means // different things depending on the way // the Comparable interface is implemented: System.out.println("Collections.max(c) = " + Collections.max(c)); System.out.println("Collections.min(c) = " + Collections.min(c)); // Add a Collection to another Collection Collection c2 = new ArrayList(); Collections2.fill(c2, Collections2.countries, 5); c.addAll(c2); System.out.println(c); c.remove(CountryCapitals.pairs[0][0]); System.out.println(c); c.remove(CountryCapitals.pairs[1][0]); System.out.println(c); // Remove all components that are // in the argument collection: c.removeAll(c2); System.out.println(c); c.addAll(c2); System.out.println(c); // Is an element in this Collection? String val = CountryCapitals.pairs[3][0]; System.out.println("c.contains(" + val + ") = " + c.contains(val)); // Is a Collection in this Collection? System.out.println( "c.containsAll(c2) = " + c.containsAll(c2)); Collection c3 = ((List)c).subList(3, 5); // Keep all the elements that are in both // c2 and c3 (an intersection of sets): c2.retainAll(c3); System.out.println(c); // Throw away all the elements // in c2 that also appear in c3: c2.removeAll(c3); System.out.println("c.isEmpty() = " + c.isEmpty()); c = new ArrayList(); Collections2.fill(c, Collections2.countries, 5); System.out.println(c); c.clear(); // Remove all elements System.out.println("after c.clear():"); System.out.println(c); monitor.expect(new String[] { "[ALGERIA, ANGOLA, BENIN, BOTSWANA, BURKINA FASO, " + "ten, eleven]", "Collections.max(c) = ten", "Collections.min(c) = ALGERIA", "[ALGERIA, ANGOLA, BENIN, BOTSWANA, BURKINA FASO, " + "ten, eleven, BURUNDI, CAMEROON, CAPE VERDE, " + "CENTRAL AFRICAN REPUBLIC, CHAD]", "[ANGOLA, BENIN, BOTSWANA, BURKINA FASO, ten, " + "eleven, BURUNDI, CAMEROON, CAPE VERDE, " + "CENTRAL AFRICAN REPUBLIC, CHAD]", "[BENIN, BOTSWANA, BURKINA FASO, ten, eleven, " + "BURUNDI, CAMEROON, CAPE VERDE, " + "CENTRAL AFRICAN REPUBLIC, CHAD]", "[BENIN, BOTSWANA, BURKINA FASO, ten, eleven]", "[BENIN, BOTSWANA, BURKINA FASO, ten, eleven, " + "BURUNDI, CAMEROON, CAPE VERDE, " + "CENTRAL AFRICAN REPUBLIC, CHAD]", "c.contains(BOTSWANA) = true", "c.containsAll(c2) = true", "[BENIN, BOTSWANA, BURKINA FASO, ten, eleven, " + "BURUNDI, CAMEROON, CAPE VERDE, " + "CENTRAL AFRICAN REPUBLIC, CHAD]", "c.isEmpty() = false", "[COMOROS, CONGO, DJIBOUTI, EGYPT, " + "EQUATORIAL GUINEA]", "after c.clear():", "[]" }); } } ///:~ ---------- Java Compile ---------- Collection1.java:50: reference to List is ambiguous, both class com.bruceeckel.util.List in com.bruceeckel.util and class java.util.List in java.util match Collection c3 = ((List)c).subList(3, 5); ^ Collection1.java:50: cannot find symbol symbol : method subList(int,int) location: class com.bruceeckel.util.List Collection c3 = ((List)c).subList(3, 5); ^ Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 2 errors Normal Termination I don't find List.java or List.class in the package Of com\bruceeckel\util(windows system),please all help me ,thanks in advance.
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
|
Best practice is not to use wildcard (*) imports. If you always import each class explicitly, you will not have these problems.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
yuqing ma
Greenhorn
Joined: Nov 10, 2004
Posts: 11
|
|
|
I see,thank you,Peter Chase.
|
 |
 |
|
|
subject: reference to List(interface) is ambiguous
|
|
|
|