Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Type erasure and reification
class Example {
println("Constructing an Example object: " + this)
object Test extends App {
// Return a new object of type T when called as f[T]
def f[T : Manifest] = manifest[T].erasure.getConstructor().newInstance()
// Return a string with the name of the class when called as name[T]
def name[T : Manifest] = manifest[T].toString
// This will print something like:
// Example
// Constructing an Example object: Example@74b23210
// Example@74b23210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.