• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

questions on marker interfaces

 
ritwik roy
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a complete answer to your question, but the Java Intermediate FAQ has an entry on marker interfaces.
 
Nagendra Dhulipudi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Gaze Lee
 
Gaze Lee
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic