private List lstUser = new List();无法实例化
时间: 2024-02-17 19:03:52 浏览: 17
这个问题可能是因为您没有指定List的类型参数,导致无法实例化。请尝试将List的定义改为:
```
private List<User> lstUser = new List<User>();
```
其中,User是您定义的类名,代表列表中存储的对象类型。这样就可以正确实例化List对象了。
相关问题
public class InternetFoodOrderSystem { private static BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); private static PrintWriter stdOut = new PrintWriter(System.out, true); private static PrintWriter stdErr = new PrintWriter(System.err, true); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); private ShopList shopList = new ShopList(); private OrderRecordList orderRecordList = new OrderRecordList(); private List<Customer> customersList = new ArrayList<Customer>();
这是一个Java类的定义,名为InternetFoodOrderSystem。该类包含了一些静态成员变量和实例变量,以及两个类成员变量:shopList和orderRecordList,分别是ShopList类和OrderRecordList类的实例。还有一个customersList,是一个泛型列表,用于存储Customer类的实例。该类的主要作用是实现一个网络食品订单系统。
其中,stdIn、stdOut和stdErr是三个静态成员变量,分别是BufferedReader、PrintWriter和PrintWriter类的实例。用于处理控制台输入输出。simpleDateFormat是一个SimpleDateFormat类的实例,用于格式化日期。
在类定义中还没有方法的定义,只是声明了类的变量和引用。
private List<Student> studentList;什么意思
private List<Student> studentList; 是一行代码,表示定义了一个私有的列表(List),列表中的元素类型为Student。
具体解释如下:
- private:表示该列表是私有的,只能在类内部访问,无法被外部类或对象直接访问。
- List<Student>:表示该列表中的元素类型为Student,即只能存储Student对象。
- studentList:表示列表的名称,可以根据需要自定义命名。
通过这行代码,我们可以创建一个私有的列表,用于存储学生对象。例如,可以使用以下代码来实例化并操作该列表:
```
List<Student> studentList = new ArrayList<>(); // 创建一个空的学生列表
Student student1 = new Student("John", 20); // 创建一个学生对象
studentList.add(student1); // 将学生对象添加到列表中
Student student2 = new Student("Jane", 22);
studentList.add(student2);
// 遍历列表中的学生对象
for (Student student : studentList) {
System.out.println(student.getName() + ", " + student.getAge());
}
```
上述代码中,我们创建了一个名为studentList的列表,用于存储学生对象。然后,我们创建了两个学生对象,并通过add()方法将它们添加到列表中。最后,通过for-each循环遍历列表中的学生对象,并打印出每个学生的姓名和年龄。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)