where place instance of anonymous class?
public class myclass { // variables private api api; // functions public void callapi() { api.get(<...>, responselistener) } // put that? top of file, bottom, next function? private responselistener responselistener = new responselistener() { @override public void onsuccess(object response) { } }; } and also, in case, preferable instantiate directly in api call?
public void callapi() { api.get(<...>, new responselistener() { @override public void onsuccess(object response) { } }); }
that's decision make. way wrote originally, have field called responselistener gets initialized once , reused on each callapi() invocation. if that's behavior want, put above callapi() method (with other field, api). or leave is. they're both ok, it's prefer.
if, however, want new instance each time callapi() invoked, make sense put inside callapi().
so matters whether put inside callapi() or outside, can decide better. , if want outside, doesn't matter outside, , again can decide better.
Comments
Post a Comment