• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I make an Interface as marker Interface

 
Waez Ali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Waez Ali
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,

Can You Please provide me sample Code.

Waiting For sample Code...
Thanks.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
I was waiting for your reply,
I got it now how to make marker Interface.

Thanks...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic