Deprecated
since 9.
This class and the Observer interface have been deprecated.
The event model supported by Observer and Observable
is quite limited, the order of notifications delivered by
Observable is unspecified, and state changes are not in
one-for-one correspondence with notifications.
For a richer event model, consider using the
java. package. For reliable and ordered
messaging among threads, consider using one of the concurrent data
structures in the java. package.
For reactive streams style programming, see the
java. API.
An observable object can have one or more observers. An observer
may be any object that implements interface Observer. After an
observable instance changes, an application calling the
Observable's notifyObservers method
causes all of its observers to be notified of the change by a call
to their update method.
The order in which notifications will be delivered is unspecified. The default implementation provided in the Observable class will notify Observers in the order in which they registered interest, but subclasses may change this order, use no guaranteed order, deliver notifications on separate threads, or may guarantee that their subclass follows this order, as they choose.
Note that this notification mechanism has nothing to do with threads
and is completely separate from the wait and notify
mechanism of class Object.
When an observable object is newly created, its set of observers is
empty. Two observers are considered the same if and only if the
equals method returns true for them.
java.util.Observable#notifyObservers() , java.util.Observable#notifyObservers(java.lang.Object) , java.util.Observer , java.util.Observer#update(java.util.Observable, java.lang.Object)
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized void | addObserver(Observer
an observer to be added. o)
References Deprecated
Observer is deprecated or references (maybe indirectly) at least one deprecated element.
Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set. |
| protected synchronized void | clearChanged()
Indicates that this object has no longer changed, or that it has
already notified all of its observers of its most recent change,
so that the |
| public synchronized int | Returns: the number of observers of this object.Returns the number of observers of this |
| public synchronized void | deleteObserver(Observer
the observer to be deleted. o)
References Deprecated
Observer is deprecated or references (maybe indirectly) at least one deprecated element.
Deletes an observer from the set of observers of this object. |
| public synchronized void | |
| public synchronized boolean | Returns: true if and only if the setChanged
method has been called more recently than the
clearChanged method on this object;
false otherwise.Tests if this object has changed. |
| public void | notifyObservers()
If this object has changed, as indicated by the
|
| public void | notifyObservers(Object
any object. arg)If this object has changed, as indicated by the
|
| protected synchronized void | setChanged()
Marks this |
| changed | back to summary |
|---|---|
| private boolean changed | |
| obs | back to summary |
|---|---|
| private Vector<Observer> obs | |
| Observable | back to summary |
|---|---|
| public Observable() Construct an Observable with zero Observers. | |
| addObserver | back to summary |
|---|---|
| public synchronized void addObserver(Observer o)
References Deprecated
See corresponding docs for further information. Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set. The order in which notifications will be delivered to multiple observers is not specified. See the class comment.
| |
| clearChanged | back to summary |
|---|---|
| protected synchronized void clearChanged() Indicates that this object has no longer changed, or that it has
already notified all of its observers of its most recent change,
so that the | |
| countObservers | back to summary |
|---|---|
| public synchronized int countObservers() Returns the number of observers of this
| |
| deleteObserver | back to summary |
|---|---|
| public synchronized void deleteObserver(Observer o)
References Deprecated
See corresponding docs for further information. Deletes an observer from the set of observers of this object.
Passing
| |
| deleteObservers | back to summary |
|---|---|
| public synchronized void deleteObservers() Clears the observer list so that this object no longer has any observers. | |
| hasChanged | back to summary |
|---|---|
| public synchronized boolean hasChanged() Tests if this object has changed.
| |
| notifyObservers | back to summary |
|---|---|
| public void notifyObservers() If this object has changed, as indicated by the
Each observer has its
| |
| notifyObservers | back to summary |
|---|---|
| public void notifyObservers(Object arg) If this object has changed, as indicated by the
Each observer has its
| |
| setChanged | back to summary |
|---|---|
| protected synchronized void setChanged() Marks this | |