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}
finally
so
// Do some work here ...SomeObject so = new SomeObject();try { so.DoUsefulThings();} finally { so.CleanUp();}
so
SomeObject
so
so.CleanUp
try
finally
try
-finally
so
SomeObject
SomeObject
try
-finally
try
-finally
so
null
finally
NullPointerException
finally

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 }}
添加回答
举报