Created
October 25, 2020 16:02
-
-
Save rupeshtr78/24128832d889e65b61f3f640c846f729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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