public float getFloat(int p) throws ClassCastException
{
...
}
其中throws ClassCastException的作用是什么

解决方案 »

  1.   

    说明这个方法可能会抛出ClassCastException,这个是类型转换异常,调用这个方法时你必须try catch或继续向上抛
      

  2.   

    是不是用这个函数的时候必须这样用:
    try
    {
    ...
    getFloat();
    ...
    }
    catch()
    {
    ...
    }
      

  3.   

    是的,或者在你调用这个方法的方法上throws ClassCastException
      

  4.   

    并不一定必须try catch,得看你的异常是什么类型了。
      

  5.   

    在调用该方法的方法上抛异常,
    也就是调用该方法的方法 必须try{}catch(ClassCastException x)或再次throws ClassCastException 不然会出错
      

  6.   

    继承于Exception (RuntimeException子类对象除外)的异常必须得try{}catch
      

  7.   

    抛出ClassCastException类的异常.你可以try{}catch{}把那个方法写到try里面
      

  8.   

    说明你的参数不能转换成浮点数 比如任取一个asd 它就不能转换成浮点数 此时就会抛出异常
    凡是会抛出异常的函数都会在参数括号后加上 throws + 异常类名 来进行声明的。只要你看
    完一本java书 应该就会这种语法了