Here's the important part of the error message: "and therefore is overridden by the specific cloning method in the class object."
You must ensure that the clone
method is implemented in your statement. This is not ideal, but it is what you need to do, since clone
is a concrete method on Object
.
trait TraitWithClone extends Cloneable { override def clone: CloneResult = throw new CloneNotSupportedException }
Although, as a rule, you just do it right in your concrete class:
class Foo extends Cloneable { override def clone: Foo = super.clone.asInstanceOf[Foo] } scala> new Foo res0: Foo = Foo@28cc5c6c scala> res2.clone res1: Foo = Foo@7ca9bd
leedm777
source share