Fahad/CodeSamples/CompoundTypes.scala
author Chengsong
Sat, 05 Feb 2022 15:30:45 +0000
changeset 413 b85f8e28fbd8
parent 44 a751aa1ee4f7
permissions -rw-r--r--
merge

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
  }
}