문제

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