scala - Accessing self-type fields with a trait reference -
if have trait structural self type
sealed trait userview { self: {val userwrapper: userwrapper} => .... }
and object uv
of type userview
, why doesn't uv.userwrapper
work?
well, self visible? right, inside definition of trait or object extending it. condition instance has satisfy, not have effect on type userview itself. why it? constraint on type self-reference.
self-types useful declare such constraints without putting in interface of type. can declare trait requires interface when mixed in.
if want instances have field, why not use abstract definition:
sealed trait userview { def userwrapper: userwrapper }
you can implement using def or val.
Comments
Post a Comment