Can anyone explain the subtype(<:) in the following code? Why it could be used like that? When we use that? Thanks.
trait SwingApi {
type ValueChange
By virtue of the abstract type members ValueChanged
and ButtonClicked
, trait SwingApi
is itself uninstantiable (all traits are, but if they are fully implemented, they are trivially turned into a concrete class that can be instantiated).
These constraints say that instantiable subtypes of SwingApi
must define ValueChanged
and ButtonClicked
as subtypes of Event
.
The type aliases TextField
and Button
are constrained as structural types (they need not particular subclass relationship, but simply must supply the specified members with the specified types).
The why of it is simply generality. This imposes the minimal constraints on the implementors of trait SwingApi
necessary for it to be used by code that demands a SwingApi
.