jeudi 17 novembre 2016

What was the official reason why the Observer interface and Observable class became deprecated in Java SE 9?

I was surfing through the documentation for Java SE 9, and found that something (the Observer interface and Observable class) I’m currently using got slapped with the deprecated annotation. I would like to know the official reasons why this happened so I can custom make a version of my own while avoiding what the official Java API developers believed to be wrong with it.

I read this post beforehand: Java observer and observable

The problem with the Observable implementation in Java is that it comes from JDK 1.0, that is not necessary bad, but it wasn't updated since them :(.

Apart from that I don't see any issues with it, but take account that Observable doesn't use weak references for the observers (WeakReference appeared in Java 1.2), so you have to take care to always call to deleteObserver to not generate leaks when the observer is no longer necessary.

as stated by Diego

And this post: Is it bad design to have models using both Observer and Observable in Java?

First of all usually it is a bad idea to use Observable since you need to extend this class to use it.

as stated by Cratylus

Note, before this question is eagerly closed: To fit Stack Overflow's Q&A format: I'm looking for authoritative citations only, not speculation. An authoritative answer to this question will likely help many future visitors of this question, so please do not close it eagerly.

Aucun commentaire:

Enregistrer un commentaire