Why wasn't the .clone()
method specified in the java.lang.Cloneable
interface ?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
On the project I work on, we've created an interface called PublicCloneable, it contains the clone method and specifies that it is public.
I find this one useful: the fact that there's a clone method, but you cannot access it doesn't help very much.
Because the clone method is implemented in the Object class due to its "special" condition: the memory copy of objects of any kind.
In Java, there is this concept of marker interfaces. The
Cloneable
interface has no methods or fields and serves only to identify the semantics of being cloneable.from the dev-x website:
Basically, it's a broken interface. Ken Arnold and Bill Venners discussed it in Java Design Issues.
Arnold:
See this bug in the Java bugs database:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4098033
Essentially, this is a design flaw in earlier versions of Java that they are not intending to fix in the Cloneable interface as to do so would break compatibility with some existing code.