Fahad/CodeSamples/CompoundTypes.scala
author Chengsong
Mon, 04 Feb 2019 13:10:26 +0000
changeset 304 82a99eec5b73
parent 44 a751aa1ee4f7
permissions -rw-r--r--
3 files to be compiled together and then run scala Spiral a b where a, b are integers to see the time distribution

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