求教泛型的问题
初学java,程序如下:import java.util.*;
class Student
{
String name;int number;float score;
Student(String name,int number,float score)
{
this.name=name;
this.number=number;
this.score=score;
}
}
public class Example
{
public static void main (String arg[])
{
LinkedList mylist = new LinkedList();
Student stu1=new Student("赵",01,60.0f),
stu2=new Student("钱",02,70.0f),
stu3=new Student("孙",03,80.0f),
stu4=new Student("李",04,90.0f);
mylist.add(stu1);
mylist.add(stu2);
mylist.add(stu3);
mylist.add(stu4);
Iterator iter = mylist.iterator();
while (iter.hasNext())
{
Student te=(Student)iter.next();
System.out.println(te.name+" "+te.number+" "+te.score);
}
}
}
编译能通过,答案输出也正确。但是编译时会提示“使用了未经检查或不安全的操作。”
好像应该是泛型的问题,但是不明白怎么写。
如果直接改成
LinkedList<String> mylist = new LinkedList<String>();
编译都过不了了。