java - How to force the compiler to show warning messages? -



java - How to force the compiler to show warning messages? -

writing next code...

classpathxmlapplicationcontext applicationcontext = new classpathxmlapplicationcontext("mycontext.xml");

...will forcefulness eclipse show warning

resource leak: 'applicationcontext' never closed

this because should phone call applicationcontext.close()

how can myself ? how can instruct user should phone call specific method before or after using objects instantiated classes wrote ?

unfortunately cannot in general. saw try-with-resources functionality of java 7.

public class myclose implements autocloseable { @override public void close() { } }

fine:

try (myclass x = new myclass()) { ... } // automatic close

fine too:

myclass x = null;+ seek { x = new myclass(); ... } { x.close(); }

warning:

myclass x = new myclass(); ...

it autocloseable leads ide attend missing close()/try. 1 of reasons clicking on warning proposes repair try-with-resources (in ides).

however there code design pattern

class servicebaseclass { protected z z; protected yourbaseclass() { } public final void process(x x) { z = ...; ... f(x, y); ... g(x); } protected void f(x x, y y) { } protected void g(x x) { ... z ... } }

here 1 lets kid class implement (override) f , g - requirements -, , takes care process logic done oneself, in public final process - service -.

java compiler-warnings

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -