我正在寻求咨询意见,因为我操作以下法典时有错误:
public class Test9 {
public static void main(String[] args) {
Object [] myObjects = {
new Integer(12),
new String("foo"),
new Integer(5),
new Boolean(true)
};
Arrays.sort(myObjects);
for(int i=0; i<myObjects.length; i++) {
System.out.print(myObjects[i].toString());
//System.out.print(" ");
}
}
}
我发现的错误是:
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at java.lang.Integer.compareTo(Unknown Source)
at java.util.Arrays.mergeSort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at Practicequestions.Test9.main(Test9.java:18)