结论:
1.finally中的语句 如果没有加入return,是在try,catch 中,return执行表达式之后,return执行返回操作之前执行; 2.finally中的语句 如果还有return,方法会提现返回,返回的结果是finally中return 的执行
package lambda; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; /** * TODO * * @author zhaoJs * @version 1.0 * @date 2022/9/19 9:24 */ @SpringBootTest(classes = FinallyTest.class) @RunWith(SpringRunner.class) @Slf4j public class FinallyTest { public int getTt(){ int a = 1; try { int h = 0; a = a/h; return a + 1; } catch (Exception e) { return a + 2; } finally { a = 30; return a; } } @Test public void finallyTt(){ log.info(getTt() + ""); } }View Code
标签:return,try,finally,import,catch,org From: https://www.cnblogs.com/nextgg/p/16706703.html