Created
November 26, 2011 21:53
-
-
Save seadowg/1396357 to your computer and use it in GitHub Desktop.
`.class` in Scala
This file contains hidden or 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
// I always run into massive problems when trying to write Scala that uses Java libraries. Recently | |
// one thing that threw me off was trying to do the following: | |
val class = MyAwesomeType.class | |
// This is often used in Java to get the 'Class' class for a class (yeah, I know). But how do we do | |
// this in Scala? | |
val class = MyAwesomeType.class // No. This reports that there is no 'class' member for the type | |
val class = MyAwesomeType.getClass // No. This would work on a Scala 'Any' but not on a Java 'Object'. | |
val class = classOf[MyAwesomeType] // Yes. There now you know and you can stop worrying about it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment