What is the use of marker interfaces in Java?

Joshua Bloch: Effective Java 2nd Edition, p 179

Item 37: Use marker interfaces to define types


You may hear it said that marker
annotations (Item 35) make marker
interfaces obsolete. This assertion is
incorrect. Marker interfaces have two
advantages over marker annotations.
First and foremost, marker interfaces
define a type that is implemented by
instances of the marked class; marker
annotations do not. The existence of
this type allows you to catch errors
at compile time that you couldn’t
catch until runtime if you used a
marker annotation….

Personally I think I’ll bow to Joshua’s superior knowledge on this subject.

Leave a Comment