我ArrayList从类创建了一个对象数组,Student并且Student该类不是instanceofComparable接口,所以当我用ArrayList此代码编写代码时,会导致编译错误。import java.util.*;public class test {    public static void main(String[] args) {     ArrayList <Student> studentList = new ArrayList<>();     studentList.add(new Student("Ahmed",50));     studentList.add(new Student("Ameen",30));     java.util.Collections.sort(studentList);     System.out.println(studentList);}  }public class Student {    private String name;    private int score;    Student ( String name , int score){        this.name= name;        this.score = score;       }}当我用对象数组编写代码时,这会导致运行时错误import java.util.*;public class test {    public static void main(String[] args) {      Student [] student = new Student[2];      student[0]=new Student("Ahmed",50);      student[1]=new Student("Ameen",30);     java.util.Arrays.sort(student);     System.out.println(Arrays.toString(student));}}public class Student {    private String name;    private int score;    Student ( String name , int score){        this.name= name;        this.score = score;       }}我的问题是为什么我在数组列表中出现编译错误,为什么在对象数组中出现运行时错误?谢谢。
                    
                    
                添加回答
举报
0/150
	提交
		取消
	