3 回答

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個贊

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超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貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超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 }}
添加回答
舉報(bào)