2類型轉換異常:Exception in thread "main" java.lang.ClassCastException:java.lang.Object cannot be cast to java.lang.Integer
阿新 • • 發佈:2017-06-29
cnblogs color pan rgs main string [] 類型 style
public class TestException {
public static void main(String[] args) {
Object obj = new Integer(1);
int i =(Integer)(obj);
System.out.println(i);
Object object = new Object();
if (object instanceof Integer){
System.out.println(true);
}
int j = (Integer)object;
System.out.println(j);
}
}
1 Exception in thread "main" java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.Integer at TestException.main(TestException.java:8)
2類型轉換異常:Exception in thread "main" java.lang.ClassCastException:java.lang.Object cannot be cast to java.lang.Integer