Let this class structure:
public interface TypeIdentifiable {} public interface TypeCloneable extends Cloneable { public Object clone() throws CloneNotSupportedException; } public class Foo implements TypeCloneable, TypeIdentifiable { @Override public Object clone() throws CloneNotSupportedException {
I have this compilation error (although the IDE, Intellij in my case, cannot show an encoding error)
Error:(4, 37) java: clone() in java.lang.Object cannot implement clone() in foo.TypeCloneable attempting to assign weaker access privileges; was public
I know that the compiler is trying to call the clone() method from Object instead of TypeCloneable , but I don't understand why. I also tried casting it to TypeCloneable (I assumed that the compiler knows which clone() method calls in this case, but the same problem).
public void foo(T element) throws Exception { TypeCloneable typeCloneable = (TypeCloneable) element; TypeCloneable cloned = (TypeCloneable) typeCloneable.clone(); }
I'm a little confused ... Can I do something here to force callling clone () from TypeCloneable?
Thanks for the adpp
source share