收集一些常用的代码
 

有趣:Case Block中的变量声明

有以下代码:

        switch (a) {

            case 1:

                int b; break;

            case 2:

                b = 1;  System.out.println("b = " + b);break; 

        }

问:

      如果a是2,会有什么结果?


解释:

      Declarations are processed at compile time and do not depend on the execution flow of your code. Since b is declared within the local scope of the switch block, it is useable anywhere in that block from the point of its declaration. 


本文由尤慕译自CodeRanch

2012-07-10 /
标签: java
 
评论
© 代码|Powered by LOFTER