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();
}
}
}
myMethod()executes afterdoSomethingbecausedoSomethingis executed beforebarMethodreturns its value to the caller.The value gets calculated and prepared to be returned, then the
finallyblock executes in its entirety, and only then the caller gets to proceed; this is whenmyMethodgets called.