Possible duplicate:
Anonymous vs called inner classes? - best practics?
When working with Java Handlers in general, people often use three approaches:
- Create a class that will implement all the necessary interfaces.
- Create
anonymous inner class - Create a
local class
I'm only interested in the differences between 2) and 3)
Comparing 2) with 3), we can consider the following code. In this example, the compiler will generate only one class .
class MyHandler implements ClickHandler, DragHandler, MovedHandler { public void onClick(ClickEvent clickEvent) {
In the following example, three inner classes will be generated by the compiler (correct me if I am wrong).
button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent clickEvent) {
My question is: is there any other difference between the two approaches? Are there any reservations about using one, despite the other?
source share