Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created October 29, 2015 04:20
Show Gist options
  • Save puffnfresh/5852cd41c30604342fa2 to your computer and use it in GitHub Desktop.
Save puffnfresh/5852cd41c30604342fa2 to your computer and use it in GitHub Desktop.
null.asInstanceOf[Int].asInstanceOf[String]
scala> null.asInstanceOf[Int]
res0: Int = 0
scala> 0.asInstanceOf[String]
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
... 33 elided
scala> null.asInstanceOf[Int].asInstanceOf[String]
res2: String = null
@xuwei-k
Copy link

xuwei-k commented Oct 29, 2015

http://stackoverflow.com/a/10750800

depends on the context in which it is done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment