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.
Questions tagged [scala-reflect]
278 questions
0
votes
1 answer
scala how to use pattern matching with inheriance and templated class
We use at our company a data structure that looks like that:
trait Resource
case class templatedResource[T](t: T) extends Resource
case class BParameter()
case class CParameter()
object B {
type Resource =…

JR Utily
- 1,792
- 1
- 23
- 38
0
votes
1 answer
Have Implementation in Classpath code to be used in Library
I am trying to write a Utility library (jar),
Inside Library
interface ConfigBuilder
{
public Configuration buildConfiguration()
}
class SomeLogic
{
private void someMethod()
{
ConfigBuilder builder = // GET IMPLEMETATION OBJECT FROM…

Nirbhay Mishra
- 1,629
- 3
- 19
- 35
0
votes
1 answer
Calling a method from Annotation using reflection
I have Sample class with Size annotation
case class Sample(
attr: SomeTypeA
@Size(value = 50)
name: SomeTypeB)
This Size annotation is a class that implements AnnotationInterface
trait AnnotationInterface[T] {
def getValue: T
}
class…

yuntres
- 47
- 1
- 1
- 6
0
votes
1 answer
Instantiate a class with a specified name
I'm writing a Scala library to operate upon Spark DataFrames. I have a bunch of classes, each of which contain a function that operates upon the supplied DataFrame:
class Foo(){val func = SomeFunction(,,,)}
class Bar(){val func =…

jamiet
- 10,501
- 14
- 80
- 159
0
votes
1 answer
Scala Reflection to generate a companion object and call the apply method
Here is the problem.
trait TestTrait[T, R] extends (T => R)
// Class implementing TestTrait. This is one class, there are a number of class implementing TestTrait
class TestClass(val input: Map[String, String])extends…

Arjun Karnwal
- 379
- 3
- 13
0
votes
1 answer
scala AST Select node can't find members inherited from parent
I'm writing a macro called assign whose job is to assign values from members of one instance to another with a particular prefix added to the name of the member. For example, I have an instance with members named my_prefix_data, my_prefix_rden, ...…

alcorn
- 1,268
- 1
- 8
- 17
0
votes
1 answer
Scala reflection for nested path strings
Given a string of com.company.util.Type[com.company.controller.Response], or com.company.util.Type[scala.collection.Seq[com.company.controller.Response]] how do you use reflection to instantiate com.company.controller.Response?
I could manually use…

speak
- 5,202
- 4
- 36
- 41
0
votes
1 answer
Scala: Reflection APIs to call one of the two methods with the same name
I am trying to use Scala Reflection APIs to call one of the two methods with the same name. Only difference is that one of them takes an argument but the other one doesn't. I want to call the one that doesn't take any arguments. I am trying…

DilTeam
- 2,551
- 9
- 42
- 69
0
votes
2 answers
Tensorflow in Scala reflection
I am trying to get tensorflow for java to work on Scala. I am use the tensorflow java library without any wrapper for Scala.
At sbt I have:
If I run the HelloWord found here, it WORKS fine, with the Scala adaptations:
import…

aitorhh
- 2,331
- 1
- 23
- 35
0
votes
3 answers
scala.tools.reflect.ToolBoxError: reflective compilation has failed: cannot initialize the compiler due to java.lang.VerifyError
I want to pass a scala file containing a case class so my application compiles this case class during run time and start using it.
The main reason why I am doing this is because I want to avoid rebuilding my code every time the case class changes.…

Ignacio Alorre
- 7,307
- 8
- 57
- 94
0
votes
1 answer
In scala reflection, how to resolve concrete type member?
I have a program that can yield an abstract TypeTag when executed:
class TypeResolving extends FunSpec {
import org.apache.spark.sql.catalyst.ScalaReflection.universe._
val example = new Example
it("can convert") {
val t1 =…

tribbloid
- 4,026
- 14
- 64
- 103
0
votes
1 answer
In Scala 2.11+ reflection, how to reliably convert a TypeTag and a Manifest into each other?
In this post:
Is it possible to convert a TypeTag to a Manifest?
It is indicated that a TypeTag can be converted into a Manifest using the following code:
def toManifest[T:TypeTag]: Manifest[T] = {
val t = typeTag[T]
val mirror = t.mirror
…

tribbloid
- 4,026
- 14
- 64
- 103
0
votes
1 answer
How can I reflect on a field annotation (Java) in a Scala program?
I'm using Scala 2.13 and I know there's been a lot deprecated since older versions.
I've got this annotation:
@Inherited
@Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface…

Greg
- 10,696
- 22
- 68
- 98
0
votes
1 answer
Why Scala runtime reflection no longer works on lambda?
The following simple code:
import org.scalatest.FunSpec
class RuntimeMirrorSpike extends FunSpec {
import org.apache.spark.sql.catalyst.ScalaReflection.universe._
it("can reflect lambda") {
val ll = { v: String =>
v.toInt
}
…

tribbloid
- 4,026
- 14
- 64
- 103
0
votes
1 answer
How to create instance with type parameter through scala reflection?
Here is my code
package a1
trait Algorithm[T] {
def someMethod(a: Int): T
}
package b2
import a1.Algorithm
class Word2Vec[T] extends Algorithm[T] {
def someMethod(a: Int): T = a.asInstanceOf[T]
}
package c3
import a1.Algorithm
object Main…

loner233
- 13
- 5