这是我的密码。当我试图编译它时,我得到了一个运行时错误。它在第9行给了我一个错误(contact=(anytype[])new object[max_list];)
public class ArrayBasedSortedList<AnyType extends Comparable<AnyType>>
{
private AnyType[] contact;
private static int MAX_LIST = 5;
private int numItems;
public ArrayBasedSortedList()
{
contact = (AnyType[]) new Object[MAX_LIST];
}
它给了我这个错误。
Exception in thread "main" java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class [Ljava.lang.Comparable; ([Ljava.lang.Object; and [Ljava.lang.Comparable; are in module java.base of loader 'bootstrap')
at ArrayBasedSortedList.<init>(ArrayBasedSortedList.java:9)
at test.main(test.java:5)
1条答案
按热度按时间alen0pnh1#
@试着把它改成