This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes questions on marker interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "questions on marker interfaces" Watch "questions on marker interfaces" New topic
Author

questions on marker interfaces

ritwik roy
Greenhorn

Joined: May 13, 2005
Posts: 20
hi

i have some specific questions on marker interfaces

1.Though there are no methods in marker interfaces like java.io.Serializable , how the serialization will be done?

2.The relevent clone() method could have been moved out of the Object class into the relevent Cloneable interface - and thus the Cloneable interface would no longer be marker interface. But it is not done ,why?

Thanks
Ritwik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
Not a complete answer to your question, but the Java Intermediate FAQ has an entry on marker interfaces.


Ping & DNS - my free Android networking tools app
Nagendra Dhulipudi
Greenhorn

Joined: Jun 09, 2006
Posts: 5
Hi

Im trying to answer ur first question.Ofcource it is my own analysis.
when u implement marker interfaces, JVM will come to know that this class is having this particular facility like serializable etc..
JVM has developped like that as they(sun people) know all marker interface when they r developping JVM.And we can not develop marker interfaces,y bcoz we can not change the JVM functionality.so Developping marker interfaces is reserved to sun systems only.

I think I answered ur question.I tried to say what I know abt marker interfaces.
I didn't get ur point clearly in ur second question??
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42033
    
  64
Marker interfaces are not specific to the class libraries that come with the JVM - anybody can create and use their own. Of course, the JVM wouldn't know about user-created ones. As the FAQ entry points, they should be avoided anyway (because they are a hack), and thanks to Java 5 annotations they are now quite obsolete.
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Personally I prefer them over annotations, but that's in large part because I seriously dislike those

In combination with generics they might start to get seriously abused though as a means to store disparate information in genericised collections without raising compiler errors.


42
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

Originally posted by ritwik roy:
hi

i have some specific questions on marker interfaces

1.Though there are no methods in marker interfaces like java.io.Serializable , how the serialization will be done?

I don't consider this a marker interface. Either way, if you create the marker, one can resonably assume you know what to do when you see the marker. Like say, use reflection. Serializable methods are private.

Originally posted by ritwik roy:

2.The relevent clone() method could have been moved out of the Object class into the relevent Cloneable interface - and thus the Cloneable interface would no longer be marker interface. But it is not done ,why?

Thanks
Ritwik

Because then clone() would be public. clone should not be public. Its a special facility provided by Java. clone should not be used alone, but should be used to help you construct proper copies of your objects.
[ June 12, 2006: Message edited by: Mr. C Lamont Gilbert ]
Gaze Lee
Greenhorn

Joined: Sep 03, 2012
Posts: 3
ritwik roy wrote:

1.Though there are no methods in marker interfaces like java.io.Serializable , how the serialization will be done?




I want to know,too

And clone() also have this behavior - if you just invoke super.clone() in your overrided clone() method,will return a new cloned object, who did that?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Gaze Lee wrote: who did that?

Serializable - I wont say it is bad design, since access modifier of the methods intent to be private(if it could be public then it can collide with other stream's read/writeObject method)
Cloneable- might be ;)

but I done know who did that. form java source : @author unascribed

they know, people going to complaint ;)
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch Gaze Lee
Gaze Lee
Greenhorn

Joined: Sep 03, 2012
Posts: 3
Seetharaman Venkatasamy wrote:Welcome to JavaRanch Gaze Lee


Thanks Seetharaman

I deeply agree with you .

Look at this contract about change the default serialization behavior:
Advanced Serialization
The other thing that is frequently explained about serialization is overriding the readObject and writeObject methods to change the default serialization behavior. By overriding these methods you can provide additional information to the output stream, to be read back in at deserialization time:



WHAT'S THIS ? OVERRIDING? Absolutely NOT! since your Serialized Class doesnot extends/impl any IO classes/interfaces. I think this is seriously violate Low Coupling and High Cohesion principle
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4571
    
    5

No, it's not overriding, but not for the reasons you state. Private methods can't be overridden. But there's no need to shout about it -- IOW, KeepItDown <- link

You do realize the article you quoted from is more than 10 years old, don't you?


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: questions on marker interfaces