In this simple example, I create a create a container class over a generic type:
class Student[T](val favoriteThing:T, var partner:Option[Student[T]]=None )
The first field favoriteThing
is of generic type T
and the second field is a pointer to another instance of the class, but in an Option
type, and it has a default value of None
.
I can instantiate this class and examine the first field
val s1 = new Student(42)
s1.favoriteThing
But get this runtime error when accessing the partner
field.
s1.partner
Compiler exception error: line 0: can't existentially abstract over parameterized type Student[Int]
def apply() = {
^
Appreciate any help in understanding this error.