首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

ClassCastException是一个什么样的异常?

2014-01-26 
ClassCastException是一个什么样的异常?编成时遇到一个异常API文档的描述是这样的: Thrown to indicate tha

ClassCastException是一个什么样的异常?编成时遇到一个异常API文档的描述是这样的:
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException:
Object x = new Integer(0);
System.out.println((String)x);

我还是不太明白,请大侠赐教,还有那个例子我也不太明白?

------解决方法--------------------------------------------------------
类型转换的错误。你生成了一个Integerd对象,然后要把这个对象转换为String对象。这种转换是不允许的,你可以通过String.valueOf()这个方法来转换

        

热点排行