lundi 14 août 2023

How can I detect with reflection in Scala if a contructor parameter is implicit?

Suppose I have a

class A(msg: String)(using ctx1: Int, ctx2: Long)

and I want to tell that it has 2 implicit parameters using reflection.

I tried something like

val m = runtimeMirror(getClass.getClassLoader)
println(m.classSymbol(getClass).primaryConstructor.info.paramLists)

but this recognizes only one parameter list.

Also tried isImplicit

println(m.classSymbol(getClass).primaryConstructor.info.paramLists.head.map(_.asTerm.isImplicit))

and it did not work, returned false for all.

I'm using Scala 3.3





Aucun commentaire:

Enregistrer un commentaire