Should java try blocks be scoped as tightly as possible?

后端 未结 7 1791
孤城傲影
孤城傲影 2020-12-01 00:35

I\'ve been told that there is some overhead in using the Java try-catch mechanism. So, while it is necessary to put methods that throw checked exception within a try block t

7条回答
  •  渐次进展
    2020-12-01 01:23

    The second method will generate a compiler error that reader may not have been initialized. You can get around that by initializing it to null, but that just means you could get an NPE, and there's no advantage to that.

提交回复
热议问题