8

With the arrival of Java 9, the Observable class and the Observer interface are now deprecated.

The Observable javadoc states:

[Observable] 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.beans package.

It recommends to use the java.beans package, but how does one go about using it to create an event-handler to mimic the Observer Pattern?

Jacob G.
  • 28,856
  • 5
  • 62
  • 116
  • 3
    You use `PropertyChangeListener` and `PropertyChangeSupport`. NetBeans will generate the necessary code for you if it knows you're writing a bean. – user207421 Apr 26 '17 at 21:50
  • 2
    If they're 'infinitely better' they will also do that. I consider the matter trivial. – user207421 Apr 26 '17 at 22:23
  • @JacobG. Eclipse for example with the latest jdk-9 support will not do that; it's probably work in progress – Eugene Apr 27 '17 at 06:57
  • Yeah that's why I'm wondering about how we can do it manually ourselves. – Jacob G. Apr 28 '17 at 17:40
  • @nullpointer I created this question 5 months before the duplicate... – Jacob G. Nov 17 '17 at 04:04
  • @JacobG. 1. This was unanswered. 2. Marking posts duplicate doesn't mandatorily follow on time basis. – Naman Nov 17 '17 at 04:09
  • 1
    Right place, wrong time. I deserve those points >:) – Jacob G. Nov 17 '17 at 04:10
  • 4
    Is anyone else getting tired of seeing obviously not duplicate questions being marked as duplicate all over SO? This question is about how to use Java Beans is such a manner that it replicates the functionality of Observable. It does NOT ask what to use, as does the other question. It assumes one already has decided to use Java Beans but one still needs to know how to do so. – GrantRobertson Oct 08 '18 at 23:20

0 Answers0