• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of Marker Interface

 
Karthikeyan Ramaswamy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

what is the use of Marker interface(interface have no methods).

example,

java.io.Serializable

above interface has no methods to implement.
so, my question is what is purpose for and how it's working.
and when we can write user-defined marker interface.
 
b panigrahy
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marker interface is meant for Reference type checking

Ex. if class A implements java.io.Serializable then when you transfer object of class A using ObjectOutputStream class then it will check inside writeObject(Object obj, boolean unshared) method.

Code snippet is :
if (obj instanceof Serializable) {
writeOrdinaryObject(obj, desc, unshared);
}else {
...
}

Marker is a logical term .
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It also provides functionality without the developer having to code for the same.

Cheers,
Raj.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Karthikeyan R",
Please check your private messages regarding an important administrative matter.
-Ben
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic