score:9
Accepted answer
Scala thinks that the generic parameter for primitives is scala.<Primitive>
e.g. scala.Int
. It doesn't store the type in the Java class file, though arguably it could. (Or not; depends on whether there needs to be a distinction between Int
and java.lang.Integer
; under the hood the boxed form is java.lang.Integer
, even if the compiler does a good job making you believe it is Int
.)
Anyway, Scala has its own reflection capabilities which are in flux, but with 2.10 you can find the arguments of the Option
types like so:
import scala.reflect.runtime.universe._
typeTag[Foo].tpe.members.collect{
case m: MethodSymbol if m.isCaseAccessor => m
}.foreach(m => println(m.name + " " + m.typeSignature))
and you'll get something like
quuux => scala.Option[java.lang.Integer]
quux => scala.Option[scala.Boolean]
qux => scala.Option[scala.Int]
baz => scala.Boolean
bar => scala.Int
Source: stackoverflow.com
Related Query
- Why don't Scala primitives show up as type parameters in Java reflection?
- Finding type parameters via reflection in Scala 2.10?
- Why doesn't Scala fully infer type parameters when type parameters are nested?
- Why aren't type parameters allowed in Scala auxiliary constructors?
- Why can't scala infer the type of the omitted parameters in partial application?
- why scala can't infer the type of method parameters
- Get Java reflection representation of Scala type
- Scala working with Java libraries not specifying collections' type parameters
- Why does Scala not infer the type parameters when pattern matching with @
- Why the following Scala code does not compile unless explicit type parameters are added?
- scala overrides java class method with inner class and type parameters
- Scala: how to implement a java interface that contains scala "typed" classes without their type parameters
- In Scala reflection, why reflection function on TypeTag still has type erasure?
- Get method parameters with specific annotation in aspect in scala using java reflection
- Why doesn't Scala infer type parameters the same way in my abstract class?
- Equivalent in scala to java static method with type parameters
- Why does Scala provide both multiple parameters lists and multiple parameters per list?
- Why does one select Scala type members with a hash instead of a dot?
- How to show scala doc from Java Editor in Eclipse?
- Show inferred type in Intellij Scala plugin
- Why does Scala require a return type for recursive functions?
- Any way to obtain a Java class from a Scala (2.10) type tag or symbol?
- In Scala 2.8 collections, why was the Traversable type added above Iterable?
- Why scala uses reflection to call method on structural type?
- Why this scala code reports compilation error: recursive value x needs type
- Scala perf: Why is this Scala app 30x slower than the equivalent Java app?
- Abstract Types / Type Parameters in Scala
- Why does this Scala function compile when the argument does not conform to the type constraint?
- Why does Scala choose the type 'Product' for 'for' expressions involving Either and value definitions
- Scala passing type parameters to object
More Query from same tag
- code error in code sample from "Beginning Scala"
- Scala set vs map in for comprehension
- Exclude particular test subclass in ScalaTest (maven)
- Spark build.sbt file versioning
- what good orm api will work well with scala or erlang
- slick 3 mapping custom fields
- Serialize Array[Array[Byte]] to Json
- NoSuchMethodError: java.lang.String.lines()Ljava/util/stream/Stream; when trying to run a test with ScalaMock
- Akka stream batching
- How do you delete a directory before running in ScalaTest/sbt/Intellij?
- Create an instance of a generic type in Scala?
- Less Resources not Compiling Play 2.3.7
- Scala macro modify object
- How to match string containing plus symbol (+) in scala?
- Is it possible to limit the number of errors the compiler shows?
- Split with irregular pattern (regex) SCALA
- Is providing explicitly the context bound possible in Scala?
- What is Scala's Comparable trait?
- Deprecation warning in scala
- Should service layer take objects or id's as input? Should responses be objects?
- Synchronous event triggering
- how to access key values within nested map in Scala
- Getting Configuration file config.hocon does not exist when running Docker image (Snowplow, Scala)
- ScalaTest + ScalaCheck : Cannot find implicit Arbitrary[List[Integer]]
- Is it possible to manually execute and transform a Behavior
- Getting 'unable to resolve overloaded method actorRef' error when building websockets in Play + Scala
- Domain Object Validation in play
- spark.sparkContext.textFile read a file using UTF-8 encoding
- Swapping values in an array using Pattern Matching in Scala
- Scala: how to call method without tuple argument?