没有编译器错误的java多返回语句
这是一个采访问题:
public class Demo {
public static void main(String[] args) {
System.out.println(foo());
}
static String foo() {
try {
return "try ...";
} catch (Exception e) {
return "catch ...";
} finally {
return "finally ..."; //got as result
}
}
}
我的问题是为什么没有编译时错误。当我的finally
块中有return语句时,它将从finally
而不是try
和catch
块返回。我试图用-Xlint
选项编译这段代码,它给出了如下警告
warning: [finally] finally clause cannot complete normally
共 (0) 个答案