Sunday, February 5, 2017

Scala - type bounds notation for beginners

For beginners in Scala (like me) type bounds notation causes difficulty. I tried to write  short cheat sheet with Scala type bounds notation:


Scala notation Meaning Remarks
[+T] Only subclass may be used Covariant
[-T] Only superclass may be used Contravariant
[T] Only specified type may be used Invariant
[X <: B] Declares that type variable X refers to a subtype of type B Upper type bounds
[X >: B] Declares that type variable X refers to a supertype of type B Lower type bounds

Remarks:

  • Supertype - parent type
  • Subtype - child type

See code examples on Git

No comments:

Post a Comment