Question

Regarding the observer built-in design pattern:

 java.util.Observable;
 java.util.Observer;

Does thet observation have to be serializable?

The Observer has a contract to implement an update method for callbacks on what its observing. The callback would look like this:

@Override
public void update(Observable observable, final Object observation) {
    // do some stuff with the notification
}

My question then is: the last parameter called observation, does it have to be serializable or can I notify on any kind of object?

Was it helpful?

Solution

If there was a requirement for the object to be serializable, it would have been declared as such in the interface definition. As in:

public void update(Observable observable, final Serializable observation) 

but it is not, so there is no such requirement imposed.

OTHER TIPS

No, the observation parameter does not have to be serializable. Otherwise parameters type should be Serializable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top