Does a finally block always get executed in Java?

前端 未结 30 1550
逝去的感伤
逝去的感伤 2020-11-21 07:24

Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is?

try         


        
30条回答
  •  被撕碎了的回忆
    2020-11-21 07:48

    That's actually true in any language...finally will always execute before a return statement, no matter where that return is in the method body. If that wasn't the case, the finally block wouldn't have much meaning.

提交回复
热议问题