我在debian 5上使用
java
java version “1.6.0_20”
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01,mixed mode,sharing)
为什么在以下之间有区别?
情况1:
import java.util.*;
情况2:
import java.util.*; import java.util.Arrays; import java.util.List;
为什么第一种情况不包括第二种情况?
当我明确导入数组和列表时,代码只会编译.
码:
import java.util.*; import java.util.Arrays; import java.util.List; public class Test { public static void main (String[] args) { List<Integer> i = new ArrayList(Arrays.asList(1,2,3,4,5,6,7,8,9,10)); List<Integer> j = new ArrayList(); ListIterator<Integer> n = i.listIterator(i.size()); while(n.hasPrevIoUs()) { j.add(n.prevIoUs()); } println(j); } static void println(Object o) { System.out.println(o); } static void print(Object o) { System.out.print(o); } }
当我注释第二和第三个import语句时,我得到的错误是:
nattyp@debian:~/dev/java$javac Test.java Test.java:7: cannot find symbol symbol : method asList(int,int,int) location: class Arrays List<Integer> i = new ArrayList(Arrays.asList(1,10)); ^ Note: Test.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error nattyp@debian:~/dev/java$