inheritance - Is there a "SELF" type in scala that represents the current type? -
I'm learning Scala and one thing I do not know about language:
At the time I was very comfortable programming in Leicak, and I could write a class person
with a slot list: ARRA [SELF]
in Lisac, which was the equivalent List: ARRAY [PERSON]
, because SELF
is the type of object where that slot is.
But SELF
, if I type a second class STUDENT
which gets from PERSON
, then STUDENT
changes the slot that is for SELF
for student
, hence STUDENT
in STUDENT
Instead, there will be a list of PERSON
.
Can it be done in Scala?
Thank you!
I'm not sure that this would be really useful for you, but the closest thing I could think of I this.Type
example:
Scala> Class A {val L: List [this.type] = Nil} defined class A scale & gt; New A () El Ridge 3: List [A] = List () Scale & gt; Class B is a defined class B scale & gt; New b L Ridge 4: List [B] = List ()
Comments
Post a Comment