67,549
社区成员




public static String get(){
try {
return "1";
} catch (Exception e) {
// TODO: handle exception
}finally{
System.out.println("----");
}
return "2";
}
public static void main(String[] args) {
String s = get();
System.out.println(s);
}
表争论了。。LZ执行一下就知道了
表争论了。。LZ执行一下就知道了
public static String get(){ try { return "1"; } catch (Exception e) { // TODO: handle exception }finally{ System.out.println("----"); } return "2"; } public static void main(String[] args) { String s = get(); System.out.println(s); }
[quote=引用 14 楼 HUIQQ0927 的回复:] return 和 finally 他俩到底有没有 jq 啊?
finally在任何情况下都会执行
谁能解释解释 return 和 finally,到底咋回事?
楼主的不执行是什么意思? ---- 1 只是我测试执行的结果
谁能解释解释 return 和 finally,到底咋回事?
return 和 finally 他俩到底有没有 jq 啊?
[quote=引用 2 楼 HUIQQ0927 的回复:] [quote=引用 1 楼 Test_LD 的回复:] 没啥特别的还以为能输出2的,就一点finally肯定是要执行,即使catch抛异常
public static String get(){
try {
System.out.println("返回1");
return "1";
} catch (Exception e) {
// TODO: handle exception
return "-1";
}finally{
System.out.println("返回2");
return "2";
}
}
[/quote]
这个要怎么解释