Skip to content

Instantly share code, notes, and snippets.

@ryoppy
Created December 11, 2014 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryoppy/adca226e5b42b0ba1ac8 to your computer and use it in GitHub Desktop.
Save ryoppy/adca226e5b42b0ba1ac8 to your computer and use it in GitHub Desktop.
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