What is Marker Interface and how marker interface used in java

What is Marker Interface

Answer: A marker interface is an interface with no method declarations. They just tell the compiler that the objects of the classes implementing the interfaces with no defined methods need to be treated differently. These Marker interfaces are used by other code to test for permission to do something.

Java Marker Interface:

  • Serializable
  • Clonable
  • RandomAccess

From java 1.5, Introduction of java annotation feature can be use to define Marker Interface as example shows below:

Marker Interface:

package com.javahonk.markerinterface;

interface MarketInterfaceExample {

}

 

Using Annotation Marker Interface:

@interface
AnnotationUserMarkerInterface{

}

 

One thought on “What is Marker Interface”
  1. Marker Interface is used to convey to the JVM that the class implementing an interface of this category will have some special behavior. Many thanks for sharing this tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *