Created
July 13, 2021 23:25
-
-
Save Jacke/f9c9192b43c958f5832d2013a7426d4c to your computer and use it in GitHub Desktop.
upper_type_bound ART
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 { | |
| def name: String | |
| } | |
| abstract class Pet extends Animal {} | |
| class Cat extends Pet { | |
| override def name: String = "Cat" | |
| } | |
| class Dog extends Pet { | |
| override def name: String = "Dog" | |
| } | |
| class Lion extends Animal { | |
| override def name: String = "Lion" | |
| } | |
| class PetContainer[P <: Pet](p: P) { | |
| def pet: P = p | |
| } | |
| val dogContainer = new PetContainer[Dog](new Dog) | |
| val catContainer = new PetContainer[Cat](new Cat) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment