I saw something like this today:
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
What does the following part mean?
new AClass(){ this part }
Can I “extends” and create a new instance of this class inline?
I have tried to google it, but I didnt know how what it was called =/
PS: learning java =p
It’s called an “anonymous class”… it’s a shorthand way of implementing an interface, or extending an existing class (usually an abstract “Adapter” or “Helper” class), without bothering to name it.
You see it commonly in Swing code… implementing window and mouse listeners.
This looks (at face value) like a decent discussion of the topic: http://www.javaworld.com/javaworld/javaqa/2000-03/02-qa-innerclass.html
Cheers. Keith.