return before finally in java

java

Solution

`myMethod()` executes after `doSomething` because `doSomething` is executed before `barMethod` returns its value to the caller.

The value gets calculated and prepared to be returned, then the `finally` block executes in its entirety, and only then the caller gets to proceed; this is when `myMethod` gets called.

Problem

In this case, does "myMethod()" get executed before or after "doSomething()"? ``` public class Foo { public void fooMethod() { Bar bar = new Bar(); bar.barMethod().myMethod(); } } public class Bar { public SomeClass barMethod() { try { return new SomeClass(); } finally { doSomething(); } } } ```

Original source