Status: New
Owner: liuj...@google.com
Labels: Type-Defect Priority-Medium
New issue 458 by dav.co...@gmail.com: Remove clone() from all interfaces,
it is wrong; make them extend Cloneable, instead.
http://code.google.com/p/protobuf/issues/detail?id=458
Here is the example:
public class C1<T extends C1.I1 & C1.I2> {
public interface I1 {}
public interface I2 {
I2 clone();
}
}
The code above will produce a compilation error regarding clone() hiding.
However, the code below is okay (and also is in line with Java cloning
semantics):
public class C1<T extends C1.I1 & C1.I2> {
public interface I1 {}
public interface I2 extends Cloneable {}
}
The only remedy to this compiler error is to make a combined interface and
use it instead of "&" in generics:
public class C1<T extends C1.I3> {
public interface I1 {}
public interface I2 {
I2 clone();
}
public interface I3 extends I1, I2 {}
}
In other words, the inclusion of the clone() method in an interface,
prevents combining this interface with any other (and with any classes)
using the "&" generics operator as shown above. The Message.Builder and the
likes are just a concrete example of this design anti-pattern.
And the right remedy is to remove the offending clone() method from all
interfaces and make them extend the Cloneable interface. In addition, it
will require casting after use of clone methods, or classes can freely
override it, but NOT interfaces!
What version of the product are you using? On what operating system?
I observe this on Java 1.5 - 1.7. on Windows (should be the same on any OS).
I understand the impact, but the present and future pain will only increase
with time.
Sincerely,
David
--
You received this message because you are subscribed to the Google Groups "Protocol
Buffers" group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.