3 回答
TA贡献1794条经验 获得超7个赞
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
添加回答
举报