jdevelop
jdevelop

Reputation: 12296

Get a type identified by a string in the Scala macros

I have a bunch of strings (essentially names of java.lang. classes and some custom classes). In the macro I need to add the type to the function:

q"""propKey[${resolveType(c)(argType)}]($name, classOf[$argType])"""

where argType is String.

So far I tried q"$argType" - but that adds the weird signature propKey[String("java.lang.Integer")](...)

with c.universe.TypeName- there's no method to get a c.universe.Type instance.

Upvotes: 1

Views: 203

Answers (1)

余杰水
余杰水

Reputation: 1384

c.mirror.staticClass("java.lang.String").toType

Upvotes: 2

Related Questions