Issue
When I work with IO classes like java.util.Scanner
or java.io.BufferedReader
, Eclipse displays a warning Resource leak: 'suchAndSuch' is never closed
. How can I make Eclipse display this warning for my own class when it is not closed?
What I want to know is if there is an Interface or something I need to implement to make my class be treated like the IO classes, so that it's independent of any one IDE, e.g. the command line javac
also displays a warning when a resource isn't closed.
Solution
Eclipse gives warning "never closed" for any class which implements java.io.Closeable
class X implements Closeable {
@Override
public void close() throws IOException {
}
}
...
public static void main(String[] args) throws IOException {
X x = new X(); <-- Eclipse warning
}
Answered By - Evgeniy Dorofeev