aspose file tools*
The moose likes Java in General and the fly likes How can i write marker inerface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How can i write marker inerface" Watch "How can i write marker inerface" New topic
Author

How can i write marker inerface

Thennam Pandian
Ranch Hand

Joined: Oct 11, 2005
Posts: 163
Hi,

Want to write a marker interface. Is it possible to write the marker interface?

What is the logic behind the marker interfaces?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

That's very simple, just define an interface without any methods:

You could then write classes that implement the interface. If you want to see if an object is of a type that implements the marker interface, you can use the instanceof operator to check that.

Note that since Java 5, annotations have mostly superseded marker interfaces. You'd probably want to write your own annotation instead of a marker interface if you're using Java 5 or newer.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
Consider Paul's rocket mass heater.
 
subject: How can i write marker inerface