0

How does one can distinguish the functionality if implemented marker interfaces like Serializable, Cloneable, Remote, EventListener ?

Example : class MarkerDemo implements Serializable, Cloneable, Remote, EvenListener

  • You should be able to use *instanceof* to distinguish if your instance is from a class that implements a given interface. – alainlompo Jun 27 '17 at 07:31

1 Answers1

0

Marker interface is meant to be used by a framework or library. It can be discovered through api (for exmple, method accpeting EventListener) or through reflection with the library accpeting an Object. This feature became obsolete with the introduction of annotations in Java 5

Sharon Ben Asher
  • 13,849
  • 5
  • 33
  • 47
  • 1
    I wouldn't say *obsolete*. A lot less necessary yes, and annotations give you more power. However annotations require more complex logic than a simple `instanceof` when using marker interfaces. – Kayaman Jun 27 '17 at 07:28
  • The reality is that there are little to no new Marker interfaces after Java 5. I believe had annotations existed before ,we would not even have `Serializable` and such – Sharon Ben Asher Jun 27 '17 at 07:31
  • That's probably true. I wouldn't write new marker interfaces either. – Kayaman Jun 27 '17 at 07:37
  • Thanks Sharon Ben Asher and Kayaman for the response. I think answer will remain same for Marker interface but i have got the question other way round. – Kris Rudra Jun 27 '17 at 14:41