Close a Scanner linked to System.in

后端 未结 5 1427
抹茶落季
抹茶落季 2020-11-22 02:57

I have a Scanner linked to System.in. Now, after using the Scanner, I should close it, as it is bad coding practice to leave it open.

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 03:09

    Instead of adding shield classes and stuff like that, just put a nice comment and a

            @SuppressWarnings("resource")
    

    That's good enough. And I don't seem to see a lot of drawbacks to this approach. Don't forget the comment.

提交回复
热议问题