"The Cloneable interface was intended as a mixin interface for objects to advertise that they permit cloning. Unfortunately it fails to serve this purpose ... This is a highly atypical use of interfaces and not one to be emulated ... In order for implementing the interface to have any effect on a class, it and all of its superclasses must obey a fairly complex, unenforceable and largely undocumented protocol"
Can you elaborate on the difference between calling a method in any object of any class and calling it inside the same object?If clone() is protected, then you can call it in any object of any class, but you can only call it inside the same object.
But isn't every class the subclass of Object? Therefore every class can still access clone( ).we don't want it to be accessible to every class in every package
Edwardd Lee wrote:
But isn't every class the subclass of Object? Therefore every class can still access clone( ).we don't want it to be accessible to every class in every package
Just as well we can't get into the java.lang package to access such clone() methods :wink;Henry Wong wrote:. . . any class in the "java.lang" package, should be able to access the clone() method, of any class.
Henry
Edwardd Lee wrote:
But isn't every class the subclass of Object? Therefore every class can still access clone( ).we don't want it to be accessible to every class in every package
Edwardd Lee wrote:
At the same time, you can still access the default, non-overriden clone () method class from Object class in any Cloneable objects since every object is the subclass of Object.
Edwardd Lee wrote:I hope my understanding is correct.
But I can, so I shallEdwardd Lee wrote:. . . I can't seem to edit my post . . .
Edwardd Lee wrote:The initial design to give protected access modifier to clone() byJava developers was with overriding purpose in mind.
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|