我们可以使用 return 语句吗finally堵塞。这会导致任何问题吗?
从a内返回finally
阻塞会导致exceptions
丢失。
finally 块内的 return 语句将导致 try 或 catch 块中可能引发的任何异常被丢弃。
根据Java语言规范:
如果 try 块的执行由于任何其他原因突然完成
R,然后执行finally块,然后有一个选择:
If the finally block completes normally, then the try statement
completes abruptly for reason R.
If the finally block completes abruptly for reason S, then the try
statement completes abruptly for reason S (and reason R is
discarded).
注:按照JLS 14.17- return 语句总是突然完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)