Mandatory cloneable interface in Java

后端 未结 6 1643
北恋
北恋 2021-01-06 09:01

I\'m having a small problem in Java. I have an interface called Modifiable. Objects implementing this interface are Modifiable.

I also have a ModifyCommand class (wi

6条回答
  •  孤独总比滥情好
    2021-01-06 09:52

    You don't need to redefine the clone method on the interface Modifiable.

    Check the documentation: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Cloneable.html

    I understand that you are trying to force everyone to override clone method(), but you can't do it.

    In another way, you cannot override a class on a interface:

    The clone() method is always associated whit the Object.class and not the cloneable interface. You just can override it on another object, not in a interface.

提交回复
热议问题