CastException异常怎么产生的

解决方案 »

  1.   

    你把String强制转换成ArrayList就会产生
      

  2.   

    int a= (int)new String("abc");
      

  3.   

    if(!(aInstance instanceof Something)){
       Something ss = (Something)aInstance;
    }
      

  4.   

    有些 类型或对象 之间是不能强制转换的 ,这时 会报 楼主说的异常所以 强制转换 时 请用 
    instance of 检测先
      

  5.   


    //转换异常  比如ClassCastException 类转换异常
      

  6.   

    API:public class ClassCastExceptionextends RuntimeException当试图将对象强制转换为不是实例的子类时,抛出该异常。例如,以下代码将生成一个 ClassCastException: 
         Object x = new Integer(0);
         System.out.println((String)x);
      

  7.   

    以上各种异常应该是ClassCastException,而不是CastException,但有人说ClassCastException就是CastException