62,621
社区成员
发帖
与我相关
我的任务
分享
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
int a = Test.test();
System.out.println(a);
}
static int test() {
int x = 1;
try {
return x;
}
finally
{
++x;
}
}
}
public class Test
{
/**
* @param args
*/
public static void main(String[] args)
{
int a = Test.test();
System.out.println(a);
}
static int test()
{
int x = 1;
try
{
return x;
// System.out.println("是先return了还是先finally");
}
finally
{
System.out.println("finally干活没,++x前:" + x);
++x;
System.out.println("++x后:" + x);
}
}
}
//
// 这题真坑爹,被谁翻上来了,下面是我能想到知识点:
//
// 1、++x和x++区别
//
// 2、try...finally执行
//
// 3、finally和return
//
// 4、和static{} 静态代码段区分(看的眼花,我困了估计)
//
// 5、JVM原理
static int test() {
int x = 1;
try {
return x;
}
finally
{
++x;
}
}
约等于:
static int test() {
int x = 1;
int temp = x;
++x;
return temp;
}