在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ eclipse 中 resource leak問題除了用xx.close()方法

eclipse 中 resource leak問題除了用xx.close()方法,還有其他方法嗎?

圖片描述

1.兩段代碼一致,但是為什么右側代碼會出現(xiàn)resource leak的問題?
2.除了用xx.close()方法還可以怎樣解決resource leak?

回答
編輯回答
愛礙唉

最佳實踐是使用try-with-resources:

try(Scanner in = new Scanner(System.in)){
.....
}
2018年5月28日 14:27