A while back, I was extending ActionListener but for reasons I can't fathom it stopped compiling right. I looked around and found the following method.
I don't know what this technique or concept is called, but I want to learn more about it, instead of just copy, pasting, and modifying it without understanding the mechanics behind it. Anyone know what I'm talking about?
You use it when all you need the class to do is one thing and have just one object....
Eg you have an interfface or an abstract class. All you want to do is override that method once and use it. Thats where you use anonymour classes. try googling anonymous classes for more info.
Anonymous class is class which doesn't have name. This is useful when you want some functionality is specific to some classes such as in given example the Listener method which you are implementing is not shared by another class it is totally or more specific it is made for only to the that specified object that time anonymous class is useful.
More generally, this technique is called a "callback", since it defines a method that is called back by the application at some later point in time. In Java, anonymous inner classes are used to implement it, but the technique itself is much older than that, going back at least to X-Windows.
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
a bit of art, as a gift, that will fit in a stocking