Questions tagged [scala-reflect]

In Scala 2.10, a new reflection library was introduced to add a more powerful toolkit of general reflective capabilities to Scala. Along with full-featured runtime reflection for Scala types and generics, Scala 2.10 also ships with compile-time reflection capabilities, in the form of macros, as well as the ability to reify Scala expressions into abstract syntax trees.

278 questions
0
votes
1 answer

Reflection on type members?

I know this is possible: import scala.reflect._ trait Foo[A] def isDouble[A: ClassTag](foo: Foo[A]) = classTag[A].runtimeClass == classOf[Double] object Foo1 extends Foo[Double] object Foo2 extends…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
0
votes
1 answer

Instantiating scala collections via their apply method with scala reflection

I have a tool that is trying to build instances of sub-classes of various scala collections, for example scala.collection.Seq. I don't know in advance what specific class should be built, so I am trying to use reflection to get the apply method in…
nh13
  • 1
  • 1
0
votes
1 answer

Multiproject SBT build bad symbolic reference scala-reflect runtime

I've been tasked with rewriting an old ant build script to SBT. As it happens, our suite is built up of 3 modules: A Play 2.3 front-end webserver; A back-end for retrieving data from various other systems; A middle module containing some shared…
irundaia
  • 1,720
  • 17
  • 25
0
votes
0 answers

Accessing method's AST in Scala

Is there a reflective way to access classes methods' AST? class Clazz { def hello(a: Int) = (a + 1).toLong } val src = """ class Clazz { def hello(a: Int) = (a + 1).toLong } """ I want to get something like this scala> val a…
Anton
  • 494
  • 5
  • 19
0
votes
1 answer

Possible to find parameter type methods return type in Scala where parameter is a primitive type?

Suppose I have: class X { val listPrimitive: List[Int] = null val listX: List[X] = null } and I print out the return types of each method in Scala as follows: classOf[ComplexType].getMethods().foreach { m => println(s"${m.getName}:…
user48956
  • 14,850
  • 19
  • 93
  • 154
0
votes
1 answer

Instance name at runtime with the Scala Reflection API

Lets start with the following example: class Foo { override def toString = ??? } val instanceName = new Foo() println(instanceName) // Should print "instanceName" Using the Scala Reflection API (or any other method), how can I get the name of…
metch
  • 673
  • 7
  • 14
-1
votes
1 answer

in scala how can i reflection creates the underlying type

Let's say I have the following: val int_string = "Int" I want to get a map. In the process of running the program, I need to infer its type from the data, and then create a map,like in spark…
season
  • 31
  • 5
-2
votes
1 answer

Get typeOf[Int] from typeOf[List[Int]]

what I want to do is: Get typeOf[Int] from tpe. It should generalize to any type other than Int. val tpe = typeOf[List[Int]] val ??? = typeOf[Int] Thank you.
yiksanchan
  • 1,890
  • 1
  • 13
  • 37
1 2 3
18
19