Skip to content

Instantly share code, notes, and snippets.

@seadowg
Created November 26, 2011 21:53
Show Gist options
  • Save seadowg/1396357 to your computer and use it in GitHub Desktop.
Save seadowg/1396357 to your computer and use it in GitHub Desktop.
`.class` in Scala
// 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