wood burning stoves*
The moose likes Beginning Java and the fly likes How to create your own Marker interface in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to create your own Marker interface in java?" Watch "How to create your own Marker interface in java?" New topic
Author

How to create your own Marker interface in java?

Chilkosae Cozea
Greenhorn

Joined: Mar 19, 2009
Posts: 7
Hi All,

How to create own marker interface in java? How JVM will treat that interface as Marker interface and do the required functionality?

Thanks in advance.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8994
    
    9

A marker interface is an interface which by its presence indicates certain functionality. It may or may not have methods. One example in the Java API is java.io.Serializable.

How JVM will treat that interface as Marker interface and do the required functionality?


The JVM treats a marker interface the same as any other interface. It is up to you, the programmer, to write code that detects and acts upon a marker interface.
Since this question is not IO related, I'm going to move it.


[How To Ask Questions On JavaRanch]
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Chilkosae Cozea wrote:How to create own marker interface in java?

Interface with no methods, which a class can implement to show that it has certain properties. So you can have

How JVM will treat that interface as Marker interface and do the required functionality?

JVM does nothing but mark the class as implementing the interface. You can then later check whether “objects instanceof Interface" and find out whether or not it is present. As in the case of java.io.Serializable, ObjectOutputStream does this job.

Please note you should avoid create new ones. Annotations introduce in Java 5 are a generic mechanism of adding metadata to a class.


http://muhammadkhojaye.blogspot.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create your own Marker interface in java?