mercredi 27 avril 2016

Runtime reflection - extracting Symbols using a single method

I need to extract the Symbols of some types and terms, and currently I am doing it as in the following:

val assetElem     = Asset(typeOf[Display].member(TermName("kindOfDisplay")).asMethod)
val assetElem_2   = Asset(typeOf[Heat].typeSymbol)
val assetElem_3   = Asset(typeOf[Temperature.type].termSymbol)

Is there a way how I can optimize this code by creating a generic method which I can use by only giving as its parameter the type in "typeOf"?

Something like

def asset[T](s: T): Symbol = typeOf[T].typeSymbol

Thanks for any help!





Aucun commentaire:

Enregistrer un commentaire