Here, the new keyword creates an anonymous class.
This is useful when you need a listener to perform some actions, and you want your code to group together and / or the class is “one-time”, which means that it is not used elsewhere.
Here's a link to the sun tutorial on anonymous classes. All normal class rules apply. You need to implement abstract methods or all methods when creating an interface.
Scaling is a bit different, since you can access variables declared in a class, your anonymous class is nested inside. However, you cannot access local variables from an anonymous class, unless these local variables are declared final. For example:
Button button = new Button(shell, SWT.PUSH); final String someString = "hello world!"; button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) {
If someString were declared in a more global scope, it is not.
To your second question:
Yes. You are right that what is happening in the fragment. Note that a new PropertyChangeEvent is created each time? This means that listeners that appear earlier in the list do not change the PropertyChangeEvent for elements that appear later in the list.
William Morrison
source share