找不到符号ID

仙人掌板

我有这个代码

import java.util.*;
public class Student {
    private static ArrayList [] Students = new ArrayList [10];    
    private int ID;
        public static void setList(){
            for(int i = 0; i < Students.length; i++){
                Students[i] = new ArrayList();
            }
        }
        public void setID(){
            ID = (int) (Math.random() * 90000) + 10000;
        }
        public static void addStudent(Student example){
            Students[example.ID % 10].add(example);
        }
        public static void print(){
            for(int i = 0; i < Students.length; i++){
                for(int j = 0; j < Students[i].size(); j++){
                    System.out.println(Students[i].get(j).ID);
                }
                System.out.println();
            }
        }
}

System.out.println(Students [i] .get(j).ID); 告诉我找不到符号ID。我该如何解决这个问题,基本上有一个包含学生对象的数组列表数组。我想打印对象的ID。Trynna使用数组和数组列表练习开放式寻址

乔治

由于尚未指定ArrayList的类型,因此将元素存储为Object类型。编译器给出错误,因为Object类没有名为ID的成员。

这将解决问题:

private static ArrayList<Student> [] Students = new ArrayList [10]; 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章