есть ClassCastException, я не знаю, почему не могу преобразовать Object [] в String []?
package day5;
import java.util.ArrayList;
import java.util.Arrays;
public class JavaLog {
public static void main(String[] args) throws Exception {
ArrayList<Student> pList = new ArrayList<>();
pList.add(new Student("Bob", 89));//Student("name", age)
pList.add(new Student("Mike", 78));
pList.add(new Student("John", 99));
Student[] sList = (Student[]) pList.toArray();
Arrays.sort(sList);
System.out.println(Arrays.toString(sList));
}
}
class Student implements Comparable<Student>{
...
}
когда я запускаю код, я получаю ClassCastException:
Exception in thread "main" java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [Lday5.Student; ([Ljava.lang.Object; is in module java.base of loader 'bootstrap'; [Lday5.Student; is in unnamed module of loader 'app')
at day5.JavaLog.main(JavaLog.java:13)