mercredi 26 août 2015

How to get the actual type of a generic function in Scala?

How can I get the actual type a generic function is called with?

The following example should print the type the given function f returns:

def find[A](f: Int => A): Unit = {
  print("type returned by f:" + ???)
}

If find is called with find(x => "abc") I want to get ""type returned by f: String". How can ??? be implemented in Scala 2.11?





Aucun commentaire:

Enregistrer un commentaire