Fahad/CodeSamples/CompoundTypes.scala
author Chengsong
Wed, 31 Aug 2022 23:57:42 +0100
changeset 590 988e92a70704
parent 44 a751aa1ee4f7
permissions -rw-r--r--
more chap5 and chap6 bsimp_idem

package Main

object CompoundClasses {
  trait Cloneable extends java.lang.Cloneable {
    override def clone(): Cloneable = { super.clone(); this }
  }

  trait Resetable {
    def reset: Unit
  }

  def cloneAndReset(obj: Cloneable with Resetable): Cloneable = {
    val cloned = obj.clone()
    obj.reset
    cloned
  }
}