How can I override a function of type member in Scala? -
suppose have code:
class c extends a#b { override def fun(): int = 100 } trait { type b = { def fun(): int } }
the compiler says:
class type required object{def fun(): int} found class c extends a#b { ^
how can understand error?
you cannot extend structural type in scala. structural types denote bunch of methods type has define in order used @ places structural type expected.
thus, sufficient write
class c { def fun(): int = 100 }
to pass objects of type c
variables of b
.
Comments
Post a Comment