Skip to content

Instantly share code, notes, and snippets.

@salomvary
Created November 12, 2014 09:18
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 salomvary/aa16564410e8d1fad7e4 to your computer and use it in GitHub Desktop.
Save salomvary/aa16564410e8d1fad7e4 to your computer and use it in GitHub Desktop.
Scala type ascription
scala> class Foo
defined class Foo
scala> class Bar extends Foo
defined class Bar
scala> new Foo
res6: Foo = Foo@3ace5360
scala> new Bar
res8: Bar = Bar@6506fe2b
scala> new Bar: Foo
res9: Foo = Bar@15c673a9
scala> new Bar: String
<console>:10: error: type mismatch;
found : Bar
required: String
new Bar: String
^
scala> new Bar: Any
res11: Any = Bar@50eb8271
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment