Java try-finally return design question

后端 未结 7 2326
滥情空心
滥情空心 2020-11-27 04:04

In Java, a try { ... } finally { ... } is executed somewhat unintuitively to me. As illustrated in another question, Does finally always execute in Java?, if you have a retu

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-27 04:33

    If you call javac with -Xlint, then an appropriate warning will be generated indicating that you should not call return from a finally clause. For example (compiling a simple class with the above test() method):

    javac -Xlint foo.java
    foo.java:13: warning: [finally] finally clause cannot complete normally
        }
    ^
    1 warning
    

提交回复
热议问题