Question

I use case class Equals[A >: B <: B, B] to check type equivalency, e.g.,

scala> Equals[Int, Int] 
res0: Equals[Int,Int] = Equals()

scala> Equals[Int, String]
<console>:10: error: type arguments [Int,String] do not conform to method apply's type parameter bounds [A >: B <: B,B]
              Equals[Int, String]

But when I re-declare the Equals case class as:

scala> case class Equals[A <: B >: B, B]
<console>:1: error: ']' expected but '>:' found.
     case class Equals[A <: B >: B, B]

I'd like to know why [A >: B <:B, B] works , but [A <: B >: B, B] doesn't.

Was it helpful?

Solution

According to Scala Reference Specification item 4.4 Type Parameters:

TypeParam ::= (id | ‘_’) [TypeParamClause] [‘>:’ Type] [‘<:’ Type] [‘:’ Type]

Bound sequence is A >: Lover <: Upper but not A <: Upper >: Lover

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top