Scala Types — Online notes…

Mageswaran D
Sep 6, 2018 · 1 min read

Assume that class Orange extends Fruit holds. If class Box[A] is declared, then A can be prefixed with + or -.

  • A without annotation is invariant, i.e.:
  • Box[Orange] has no inheritance relationship to Box[Fruit].
  • +A is covariant, i.e.:
  • Box[Orange] is a subtype of Box[Fruit].
  • var f: Box[Fruit] = new Box[Orange]() is allowed.
  • -A is contravariant, i.e.:
  • Box[Fruit] is a subtype of Box[Orange].
  • var f: Box[Orange] = new Box[Fruit]() is allowed.

Written by

A simple guy in pursuit of of AI and Deep Learning with Big Data tools :) @ https://www.linkedin.com/in/mageswaran1989/

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade