Created
February 20, 2022 13:05
-
-
Save wcang/9f083268f45c65144dcac8aa146357b7 to your computer and use it in GitHub Desktop.
I just realized that the code in finally block will be called when if the method exits in prior code block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Finally { | |
| public static int tryFinally() { | |
| try { | |
| return 1; | |
| } finally { | |
| System.out.println("Finally block"); | |
| } | |
| } | |
| public static void main(String[] args) { | |
| System.out.println("Answer is " + tryFinally()); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output of this code is:
Finally block
Answer is 1