I've been making a number of scanner programs, just to get used to the idea and ive noticed the same thing in each program.
Every time I make the Scanner variable, Eclipse tells me that the variable is a resource leak (it underlines the Scanners name in yellow).
Why does this happen? and how can I fix it?
I've been looking for more information but aside from generalities, I cant seem to find anything specific (links or advice would be welcome)
(Eclipse does give 2 suggestions as to how to close the leak-but I'd rather know what im doing before I do it)
(the following is an example of one of my Scanner programs)
I added code tags to your post to make it easier to read. You can do that yourself next time. Just highlight the code and click "code." Now, onto your question.
Eclipse is trying to protect you have leaking file handles. Scanner has a few constructors. Some take an InputStream or Readable. Which means someone can write code like new Scanner(new BufferedReader(...))
When opening a stream/reader, not closing it is usually a resource leak. Eclipse is picking up on this. In fact System.in is an InputStream. The problem here is that Eclipse is wrong. You don't close System.in. Making it ok to take Eclipse's advice to suppress the error. I recommend doing it on the most granular level of your choices. That way, you don't accidentally hide other real warnings in code you write later.