0

I have a function that has this signature;

def process[E: TypeTag : ClassTag](id: Int): E = {

Normally I would call it like this:

process[Item](1)

I need to call it from the place where the type of the item is stored in a variable.

tt.tpe.members.collect {
  case m if m.isMethod && m.asMethod.isCaseAccessor => m.asMethod
} foreach { member => {
  // member is a MethodSymbol that can be used to get a type
  // how to call process[??](id) from here?

I assume that I have to use reflect or returnType, but how can I pass the generic type?

Vladimir Mikhaylovskiy
  • 1,955
  • 4
  • 19
  • 28

1 Answers1

3

You can pass typeTag and classTag to the method explicitly, it will infer the type parameter from that:

process(id)(typeTag, classTag)

To figure out how to get TypeTag from Type, see here, and to get ClassTag from TypeTag, look here. To get Type from member, use member.returnType

Dima
  • 39,570
  • 6
  • 44
  • 70