score:0
Accepted answer
Use _.typeSignature.typeArgs.head
, because String
is a type argument of String*
, not its typeSymbol
.
score:0
Your parameter x
is type of String*
. That is what you get by calling:
_.typeSignature.typeSymbol
but String*
is intrepreted as Seq[String]
(as we all know). Thus calling:
_.typeSignature.typeArgs
will get you your type arguments, i.e. your desired String
.
Btw. if you want to prove that String*
is Seq
just call:
_.typeSignature.erasure
So your modified code should look like (omitting class C):
val c = C()
val r = runtimeMirror(getClass.getClassLoader).reflect(c)
val x = r.symbol.typeSignature.member(newTermName("f"))
val params = x.asMethod.paramss.head.map {
_.typeSignature.typeArgs
}
for (param <- params) {
println(param)
}
it will print List(String)
.
Enjoy
Source: stackoverflow.com
Related Query
- In Scala, how to use reflection to get the real type of varargs parameters for method
- How the get the classOf for a scala object type
- Scala - how to get the 'type' for a field using reflection api
- How can I use Scala reflection to find the self type traits?
- Should I use Unit or leave out the return type for my scala method?
- How to use Scala in IntelliJ IDEA (or: why is it so difficult to get a working IDE for Scala)?
- How to use scala reflection API to get all contained classes
- How to use the function type in scala within defined in type meaningfully?
- Scala spark: how to use dataset for a case class with the schema has snake_case?
- How do I use Scala dispatch to get the URL returned in a 301 redirect?
- How can I use the new reflection API to tell if the component type of an array conforms to a type parameter?
- How to make Reflection for getting the field value by its string name and its original type
- How do I get the runtime Class of a parameterized Type in a Scala trait
- How to ask for the same type in Scala generics without introducing a third type parameter?
- How can I get random data generated for scala case classes with the ability to "change some values" for unit testing?
- In scala macros, how to get the complete `extends` clause for a class?
- How to correctly use ambiguous implicits for type negation in Scala
- Scala 2.10 reflection: Why do I get the same type "List()" for the list and list element?
- In scala 2.11+ how to use exactly the singleton type as type evidence?
- Is it possible to use reflection to find the actual type of a field declared to be a Scala Enumeration subtype?
- How to get the proper return type when using a filter based on type in Scala
- How to use ClassTag in scala macros implemented for type
- How to see the type of a scala variable? For instance a Spark PairRDD
- How to get the COUNT of emails for each id in Scala
- How can I use the Scala sttp FetchBackend for handling JavaScript in html?
- Accounting for type parameters in a Scala generic class 'equals' method... are manifests the only way?
- How scala determines implicit type parameters for TreeSet constructor
- Scala - how come using a super-type with two generic parameters cause the scala type checker to treat the child-type differently?
- Scala runtime reflections get all the members of a specific type even for inner classes
- How to get match type with multiple type parameters to work correctly in Scala 3
More Query from same tag
- How to make enum with string constants
- Chain functions in different way
- Using Undercover with ScalaTest and Maven
- How to move contents of one element in a map to another element in Scala
- Why a scala test assertion on an object's val throws NullPointerException?
- Convert List[Map[String,Map[String,Int]]] to Map[Int,Int] in Scala
- Combining nested lists in Scala - flattened Carthesian product
- Spark Streaming to Kafka slow performance
- Losing entries when inner-joining data to a left-joined DataFrame in Spark Structured Streaming
- Scala zipWithIndex over a sequence of Strings, do something different with last entry
- What is shuffle read & shuffle write in Apache Spark
- sbt - defining custom configuration for sequential tests
- Chisel switch statement doesn't appear to work in manner outlined in official tutorial
- Nested futures in Akka
- Scala Migrations mysql support
- Why is Scala confused about the return data type?
- Check that a SPARK Dataframe column matches a Regex for all occurrences using Scala
- How to serialize a nested (generic) case class
- Is it possible writing down to RDS raw sql (PostgreSQL) using AWS/Glue/Spark shell?
- Case Class parenthesis required
- How to write an efficient groupBy-size filter in Scala, can be approximate
- Macro annotation to override toString of Scala function
- How to handle removed data from state
- Java, Play2.0,')' expected but '=' found play
- Create UUID with zeros
- Why does class name of a type in a package object contain "package" in runtime class name?
- Why shouldn't one make every Scala instance variable a lazily initialized one?
- How would one implement OCaml / F#'s "function" construct in Scala?
- getting Schema for type org.apache.spark.sql.Column is not supported while running UDF in spark dataframe
- Play 2.0 on miniserver (pogoplug)