What is marker interface in java?

What is marker interface in java?

Marker Interface in java does not contains any method or field or constant declared within it. Thus we can say, a marker interface is an empty interface.

Example of marker interface

  • Serializable, 
  • Cloneable, 
  • RandomAccess interface, and 
  • Remote interface

The question that immediately pops-up in our mind is:

  • Why would one declare an empty interface? 
  • What good is it of?

In general a common belief is that a marker interface is generally used to send some kind of signal to the JVM and instructs JVM to  treat the class implementing it in a special way.

Like, when a class implements Cloneable marker interface, it signals the compiler that the class allows creation of clones of its objects.

Generally, a marker interface is used with the instanceof operator to check if a reference type variable refers to an object whose class implements the marker interface.

Java Interview Questions

Would you like to see your article here on tutorialsinhand. Join Write4Us program by

About the Author
Sonu Pandit
I am editor in chief at responsible for managing, reviewing and sending articles/contents for final approval to get published. Connect with me@ Join write4us program & share your skill
Page Views :    Published Date : Jul 11,2020  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!