• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt about marker Interface

 
Greenhorn
Posts: 25
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a doubt about marker interface
by the meaning of marker interface it does not containing any methods.so, what is the use of marker interface please explain with example
 
Saloon Keeper
Posts: 7594
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question has been asked many, many times; please avail yourself of the "Search" link at the top of the page. There's really nothing to add to those previous answers at this point.
 
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marker interface are used to inform the compiler to add special behavior to the class implementing it.
E.g java.io.Serializable, tells the compiler that the objects of the class implementing Serializable interface can be serialized.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We've discussed this question many times before. If you do a search, you'll find many older topics that answer your question. For example:

marker interface
Marker interface
what is the meaning of marker interface?
etc.
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sumit Patil wrote:Marker interface are used to inform the compiler to add special behavior to the class implementing it.
E.g java.io.Serializable, tells the compiler that the objects of the class implementing Serializable interface can be serialized.


The compiler doesn't do anything special when it encounters a class that implements a marker interface*.
The built in marker interfaces (such as Serializable or Cloneable) are used by the JVM at runtime to decide if certain operations can be performed on an object.
But you can also create your own marker interfaces** which other parts of your code can then use to make decisions about how your code works.



* Unless you have declared a reference variable of the type of the marker interface, in which case the compiler may check if an object being assigned to this reference variable actually implements the interface. Although as the interface has no methods or fields I can't see any obvious reason for doing this.

** Although these days it is often recommended to use annotations rather than marker interfaces.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marker interfaces are those which do not declare any required methods,but signify their compatibility with certain operations. For Example, The java. io. Serializable interface and clonable are typical marker interfaces. They do not contain any methods, but classes must implement this interface in order to be serialize and de-serialized
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic