Question

I need to read the fields of a case class and do different things depending on the field's type.

I thought I'd try with a macro, reading the ValDefs and pattern matching on the TypeTree of each, but that doesn't reveal what each TypeTree represents (e.g. Ints and Strings both appear as TypeTrees).

Is there an alternative to calling typeTree.toString and matching on the values of the Strings (e.g. "String" or "Int")?

Was it helpful?

Solution

You can use TypeTree's tpe method to see the underlying type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top