List错误

来源:互联网 发布:知乎红人 编辑:程序博客网 时间:2024/06/03 16:53

使用List<e>出现The type List is not generic; it cannot be parameterized with arguments <Person>错误提示

private static List<Person> readObj(String fileName) throws Exception{File file = new File(fileName);//使用list保存读取出来的对象ArrayList<Person> list = new ArrayList<Person>();//创建流对象FileInputStream fis = new FileInputStream(file);ObjectInputStream ois = new ObjectInputStream(fis);//读取对象放入list容器中while(fis.available() > 0){list.add((Person)ois.readObject());}ois.close();return list;}



解决方案:

检查导入的宝是否正确,应该导入 java.util.list包,而不是java.awt.List;

错误:import java.awt.List;

正确:import java.util.List;