如题
- Java code
import java.util.*;class Student{ String name; Student(String name){ this.name=name; } public String getName(){ return name; }}public class LinkedList { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stubList<Student> list=new LinkedList<Student>();for(int k=1;k<=100;k++){ list.add(new Student("I am "+k));}Iterator<Student> iter=list.iterator();long time1=System.currentTimeMillis();while (iter.hasNext()){Student te=iter.next();System.out.println(te.getName()); }long time2=System.currentTimeMillis();System.out.println("用时"+(time2-time1)+"毫秒");}}
Exception in thread "main" java.lang.Error: 无法解析的编译问题:
类型 LinkedList 不是通用的;不能使用参数 <Student> 将它参数化
at LinkedList.main(LinkedList.java:22)
------解决方案--------------------
类名LinkedList 和系统类库重名。
------解决方案--------------------
public class LinkedList {
不能使用 LinkedList作为类名 ,和人家API的类名冲突
- Java code
import java.util.*;class Student{ String name; Student(String name){ this.name=name; } public String getName(){ return name; }}public class LinkedListTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stubList<Student> list=new LinkedList<Student>();for(int k=1;k<=100;k++){ list.add(new Student("I am "+k));}Iterator<Student> iter=list.iterator();long time1=System.currentTimeMillis();while (iter.hasNext()){Student te=iter.next();System.out.println(te.getName()); }long time2=System.currentTimeMillis();System.out.println("用时"+(time2-time1)+"毫秒");}}