質問

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