3 回答
TA贡献1860条经验 获得超8个赞
TA贡献1780条经验 获得超4个赞
SomeObject so;try {
// Do some work here ...
so = new SomeObject();
so.DoUsefulThings();} finally {
so.CleanUp(); // Compiler error here}finallyso
// Do some work here ...SomeObject so = new SomeObject();try {
so.DoUsefulThings();} finally {
so.CleanUp();}soSomeObjectsoso.CleanUptryfinally
try-finallysoSomeObjectSomeObjecttry-finally
try-finally
sonullfinallyNullPointerExceptionfinally
TA贡献1817条经验 获得超14个赞
SomeObject so;try {
// Do some work here ...
so = new SomeObject();
so.DoUsefulThings();} finally {
so.CleanUp(); // Compiler error here}SomeObject so = null;try {
// Do some work here ...
so = new SomeObject();
so.DoUsefulThings();} finally {
if (so != null) {
so.CleanUp(); // safe
}}添加回答
举报
