3 回答

TA貢獻1794條經驗 獲得超8個贊
Object o = "str";String str = (String)o;
String o = "str";Integer str = (Integer)o; //Compilation fails here
ClassCastException
Number o = new Integer(5);Double n = (Double)o; //ClassCastException thrown here
Integer
Number
Integer
Number
Double
, Float
, Byte
, Long

TA貢獻1854條經驗 獲得超8個贊
String
File
File
String
String
Object
String
Object
(Object
File
Object
.
File f = (File)(Object) "Stupid cast";
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.io.File
添加回答
舉報