Reputation: 23
I'm learning some Scala example from somewhere, it looks like as below:
class className[T <: classTypeA : classTypeB](some args)....
Or:
class className[T<:classTypeA with trait1](some args)...
Some tutorial explain that T <: classTypeA
means T
must be the subclass of classTypeA
.
I don't understand why there are two types after <:
, and what with trait1
means?
Upvotes: 0
Views: 56
Reputation: 27356
class className[T <: classTypeA : classTypeB](some args)
In this declaration classTypeB
is a type class and this is equivalent to
class className[T <: classTypeA](some args)(implicit ev: classTypeB[T])
There must be a suitable instance of classTypeB[T]
in scope for this to compile. This allows fine-grain control of which types are accepted as parameters to the class.
class className[T <: classTypeA with trait1](some args)
This declaration says that T
must be a subclass of the type classTypeA with trait1
.
Upvotes: 2