I've been looking through a lot of OOP Design Patterns lately, and I've run into some strange things I've never seen before:
Button button = new Button(shell, SWT.PUSH);
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Handle the selection event
System.out.println("Called!");
}
});
Specfically, what does this do (eg. what does the "new" keyword do here)?:
button.addSelectionListener(new SelectionAdapter() {
Second question:
private void notifyListeners(Object object, String property, String oldValue, String newValue) {
for (PropertyChangeListener name : listener) {
name.propertyChange(new PropertyChangeEvent(this, "firstName", oldValue, newValue));
}
}
This is a snippet from an observer design pattern. To my new understanding, the name.propertyChange(...) creates an object of PropertyChangeEvent and through Java's observer pattern implementation, automatically notifies the observers by sending this new object's information to the observers (or something very similar to this). Is this correct?