Return in a finally blockWhat will happen if we return a value in a finally block?
If the finally block executes successfully the return in the finally block will override the return value set in the try-catch block.
package org.magicworldz.basic.finallyreturn;
public class FinallyReturn {
public static void main(String[] args) {
var app = new FinallyReturn();
System.out.println(app.finallyReturn(5));
}
public int finallyReturn(int ret) {
try {
return ret;
} finally {
return 0;
}
}
}