Created
December 11, 2014 05:34
-
-
Save ryoppy/adca226e5b42b0ba1ac8 to your computer and use it in GitHub Desktop.
This file contains 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
scala> class Person | |
defined class Person | |
scala> class Bob extends Person | |
defined class Bob | |
scala> class Alice extends Person | |
defined class Alice | |
scala> class School[+A] | |
defined class School | |
scala> def in(s: School[Person]) = s | |
in: (s: School[Person])School[Person] | |
scala> in(new School[Person]) | |
res0: School[Person] = School@16b4a017 | |
scala> in(new School[Bob]) | |
res1: School[Person] = School@6f79caec | |
scala> in(new School[Alice]) | |
res2: School[Person] = School@6fffcba5 | |
scala> class Animal | |
defined class Animal | |
scala> class Cat extends Animal | |
defined class Cat | |
scala> in(new School[Cat]) | |
<console>:13: error: type mismatch; | |
found : School[Cat] | |
required: School[Person] | |
in(new School[Cat]) | |
^ | |
scala> in(new School[Cat with Bob]) | |
res4: School[Person] = School@4f970963 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment