• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Marker Interface

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Experts,
I have a common question regarding marker interface.Whats the use of a marker Interface,which has no body in it?Which part of Oops concept it is following?
Definite not Inheritance..because It has nothing to inherit.If we google it all website rather giving the proper use all will suggest "Serialize" Interface.But My point is serialize interface doesn't contain any method,so thats the use.I will create a my own user(Marker) interface ,and I will implements to the class which I want to do serialization.But In that case why It didn't work?What happens internally so that it will search for the particular serialize interface only?


I read it all the topics of Interface of javaranch
https://coderanch.com/forums/jforum?module=search&action=search&forum=24&match_type=all&sort_by=time&search_keywords=marker+interface
https://coderanch.com/how-to/java/Java-FAQ#marker

but still I have doubt.



with regards
Biswomohan Pattanaik
 
Bartender
Posts: 15735
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The point of marker interfaces is that they signify whether a certain action is allowed on a class, not whether a certain action is possible on a class.

Most of the time, these actions are extralinguistic, or implemented through reflection.

Let's take a look at the Cloneable interface. The action of cloning an object already exists, in the Object class. However, you are not allowed to clone just any object. Classes which permit their instances to be cloned through the clone() method, will implement the Cloneable interface. This interface is empty, and simply signifies that cloning is allowed for that class.
 
Biswomohan Pattanaik
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:The point of marker interfaces is that they signify whether a certain action is allowed on a class, not whether a certain action is possible on a class.

Most of the time, these actions are extralinguistic, or implemented through reflection.

Let's take a look at the Cloneable interface. The action of cloning an object already exists, in the Object class. However, you are not allowed to clone just any object. Classes which permit their instances to be cloned through the clone() method, will implement the Cloneable interface. This interface is empty, and simply signifies that cloning is allowed for that class.




Thanks Stephan van Hulst
But my point is which part of Oops concept it is following....


with regards
Biswomohan
 
Stephan van Hulst
Bartender
Posts: 15735
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simple interface implementation, I guess. What OOP concept would you call a class implementing an interface that is not a marker interface? It's not inheritance, you can only inherit from classes.

There's no difference in implementing a marker interface an implementing any other interface, other than the number of methods you should implement.

Does it really matter what OOP concept it is, if it is an OOP concept to start with?
 
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This basically is the concept of reflection ... where you just tell the compiler that your class should be allowed to implement certain functionality
 
Stephan van Hulst
Bartender
Posts: 15735
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Marker interfaces aren't always used in a reflective manner. Take a look at the RandomAccess interface. Other classes simply base their behaviour on whether or not a list implements this interface.

Also, reflection is not an OOP concept.
 
Lalit Mehra
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:

Also, reflection is not an OOP concept.



I didn't mention that it's an OOP concept ...
 
Stephan van Hulst
Bartender
Posts: 15735
368
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Haha sorry, it wasn't meant as a criticism. I just meant to clarify to the original poster that not all principles we use are part of OOP.
 
Lalit Mehra
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To van,

hey no need for a sorry buddy ...
i didn't take it as a critic remark.

i think i forgot to add this --> to the previous post
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic