سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top