If I could figure out how to “attach manifests back the generic call stack” (as Joshua writes about in section 7.2.2 of “Scala in Depth”), would that enable me to instantiate B along those lines?:
def m1[T](implicit m: Manifest[T]): T = m.erasure.newInstance.asInstanceOf[T]
class A {
def m2[T](implicit m: Manifest[T]): T = m.erasure.newInstance.asInstanceOf[T]
def inA() {
m1[A]
m2[A]
m2[B] // Doesn't work...
}
class B
}
m1[A]
val a = new A
a.m2[A]
a.inA() // boom
Or do I need some view bound?
You cannot instantiate the inner class
Blike this, because the constructor of such inner classes secretly takes a reference to an object of the outer class.newInstancecan only be called on classes that have a zero-argument constructor.