Home  >  Forum  >  Core Java
Post New Query

How to write our own marker interface



Asked on April 04, 2014
Can we create marker interface if yes
How to write our own marker interface?


Replied on April 25, 2014
Marker interface has no method. Java has built-in marker interface like Serializable, Clonable etc that are understand by JVM.
We can create our own marker interface but it has nothing to do with JVM, we can add some checks with
instanceOf.

Suppose we have an interface like


interface Marker{    }

class A implements Marker{
      //do some task
}

class Main{
         public static void main(String[] args){
            A ob = new A()[
             if (ob instanceOf Marker){
                // do some task
           }
       }
}


Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us