Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2010 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/545785 to your computer and use it in GitHub Desktop.
Save anonymous/545785 to your computer and use it in GitHub Desktop.
trait Cloneable[T <: Cloneable[_]] {
def clone(): T
}
class A(var a: Int) extends Cloneable[A] {
def clone(): A = new A(a)
}
class B(aa: Int, var b: Int) extends A(aa) with Cloneable[B] {
def clone(): B = new B(a, b)
}
/*
/home/james/proj/sblast/src/main/scala/clonetest.scala:9: illegal inheritance;
self-type B does not conform to Cloneable[B]'s selftype Cloneable[B]
class B(aa: Int, var b: Int) extends A(aa) with Cloneable[B] {
^
one error found
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment