Skip to content

Instantly share code, notes, and snippets.

@rupeshtr78
Created October 25, 2020 16:02
Show Gist options
  • Save rupeshtr78/24128832d889e65b61f3f640c846f729 to your computer and use it in GitHub Desktop.
Save rupeshtr78/24128832d889e65b61f3f640c846f729 to your computer and use it in GitHub Desktop.
abstract class Animal
class Dog(name:String) extends Animal
// if DOG <:Animal does List[Dog] <: List[Animal]
val laika = new Dog("Laika")
val lassie = new Dog("lassie")
val hachi = new Dog("hachi")
val myDogs = List(lassie,hachi,laika)
val myAnimals: List[Animal] = List(lassie, hachi, laika)
class CovarList[+T]
val covarDogs:CovarList[Animal] = new CovarList[Dog]
class InvarList[T]
val invarAnimals:InvarList[Animal] = new InvarList[Animal]
val invarDogs:InvarList[Dog] = new InvarList[Dog]
class ContraList[-T]
val contraDogs:ContraList[Dog] = new ContraList[Animal]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment