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?

Était-ce utile?

La 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.

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top