anonymous inner class - What is this in java? Attaching methods "on the fly"? -


i saw today:

    frame.addwindowlistener(new windowadapter() {          public void windowclosing(windowevent e) {             system.exit(0);         }     }); 

what following part mean?

new aclass(){ part } 

can "extends" , create new instance of class inline?

i have tried google it, didnt know how called =/

ps: learning java =p

it's called "anonymous class"... it's shorthand way of implementing interface, or extending existing class (usually abstract "adapter" or "helper" class), without bothering name it.

you see commonly in swing code... implementing window , mouse listeners.

this looks (at face value) decent discussion of topic: http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html

cheers. keith.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -