I've got troubles with cloning in Scala. Is this possible to clone an object of an arbitrary type T? Something like this:
import collection.immutable.Stack
object Tester extends App {
trait Grand[T <: Cloneable] {
val stack = Stack[T]()
val h: T
def snapshot() {
stack push h.clone().asInstanceOf[T]
}
}
}
however it throws:
scala: method clone in class Object cannot be accessed in T
Access to protected method clone not permitted because
prefix type T does not conform to
trait Grand in object Tester where the access take place
What goes wrong there?