Skip to content

Instantly share code, notes, and snippets.

@retronym
Created April 16, 2014 20:19
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 retronym/10928835 to your computer and use it in GitHub Desktop.
Save retronym/10928835 to your computer and use it in GitHub Desktop.
scala> def id[A <: AnyRef](a: A): a.type = a
id: [A <: AnyRef](a: A)a.type
scala> val c = ""; id(c): c.type
c: String = ""
res0: c.type = ""
scala> val c = ""; { val temp = c; id(temp)} : c.type
<console>:11: error: type mismatch;
found : temp.type (with underlying type String)
required: c.type
{ val temp = c; id(temp)} : c.type
^
scala> val c = ""; { val temp: c.type = c; id(temp)} : c.type
c: String = ""
res2: c.type = ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment