aspose file tools*
The moose likes Java in General and the fly likes Can I make an Interface as marker Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Can I make an Interface as marker Interface " Watch "Can I make an Interface as marker Interface " New topic
Author

Can I make an Interface as marker Interface

Waez Ali
Greenhorn

Joined: Jan 10, 2005
Posts: 22
Hi,

I just want to know can i create my own marker interface(that doesn't contain any thing) for my class.
As Cloneable,Serializable are...

So Please Let me know.

Thanks.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Of course.

Now, you also have to write any code which imparts meaning to that marker interface. Java itself won't know or care anything about it.


[Jess in Action][AskingGoodQuestions]
Waez Ali
Greenhorn

Joined: Jan 10, 2005
Posts: 22
Hi Ernest,

Can You Please provide me sample Code.

Waiting For sample Code...
Thanks.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
If you know how to define an interface, you know how to define a marker interface. Take any of the interfaces you've created and remove all method and constant declarations. Bingo, marker interface. Then use instanceof to test if an object implements your marker interface.
Waez Ali
Greenhorn

Joined: Jan 10, 2005
Posts: 22
Hi David,
I was waiting for your reply,
I got it now how to make marker Interface.

Thanks...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can I make an Interface as marker Interface