-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
In section "Covariance":
We say that
ImmutableBoxis covariant inA, and this is indicated by the+before theA.More formally, that gives us the following relationship: given some
class Cov[+T], then ifAis a subtype ofB,Cov[A]is a subtype ofCov[B]. This allows us to make very useful and intuitive subtyping relationships using generics.
In section "Contravariance":
We say that
Serializeris contravariant inA, and this is indicated by the-before theA. A more general serializer is a subtype of a more specific serializer.More formally, that gives us the reverse relationship: given some
class Contra[-T], then ifAis a subtype ofB,Contra[B]is a subtype ofContra[A].
As stated in "Generic classes":
One convention is to use the letter A as type parameter identifier, though any parameter name may be used.
class Cov[+T] should be class Cov[+A].
class Contra[-T] should be class Contra[-A].
For context:
- Starting Scala
- Started Tour from beginning, never met generic defined with T letter
- In Java, convention is to use letter T instead of A as in Scala 3 (I think this is main reason for this issue.)
Not really sure with this.
I can make a PR when confirmed.
Thanks