Skip to content

Instantly share code, notes, and snippets.

@Centaur
Created December 24, 2013 06:21
Show Gist options
  • Save Centaur/8109498 to your computer and use it in GitHub Desktop.
Save Centaur/8109498 to your computer and use it in GitHub Desktop.
MyType example
import reflect._
class Father[T <: Father[T] : ClassTag]{
def createInstance: T = implicitly[ClassTag[T]].runtimeClass.newInstance.asInstanceOf[T]
}
class Child1 extends Father[Child1]
class Child2 extends Father[Child2]
assert(new Child1().createInstance.isInstanceOf[Child1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment