今天,我和我的同事讨论了finalJava中关键字的用法,以改进垃圾收集.
例如,如果您编写如下方法:
public Double doCalc(final Double value)
{
   final Double maxWeight = 1000.0;
   final Double totalWeight = maxWeight * value;
   return totalWeight;  
}
声明方法中的变量final将有助于垃圾收集在方法退出后从方法中未使用的变量清除内存.
这是真的?
在以前的java版本中,重新抛出异常被视为抛出catch参数的类型.
例如:
public static void test() throws Exception{
    DateFormat df = new SimpleDateFormat("yyyyMMdd");
    try {
        df.parse("x20110731");
        new FileReader("file.txt").read();
    } catch (Exception e) {
        System.out.println("Caught exception: " + e.getMessage());
        throw e;
    }
}
在Java 7中,如果声明异常,则可以更精确地了解抛出的异常final:
//(doesn't compile in Java<7)
public static void test2() throws ParseException, IOException{
    DateFormat df = new SimpleDateFormat("yyyyMMdd");
    try {
        df.parse("x20110731");
        new FileReader("file.txt").read();
    } catch (final Exception e) {
        System.out.println("Caught exception: " + e.getMessage());
        throw e;
    }
}
我的问题:文档说我需要声明异常final.但如果我不这样做,上面的代码仍然编译和工作.我错过了什么吗?
参考文献: