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
Invoke static method with access only to the containing object's type
I have a TypeTag for one of several objects and I know that they extend a base trait with a known method signature. I also have access to the method's MethodSymbol if I need it. What I want to do is:
def invokeMyMethod[T: TypeTag](myMethodSymbol:…

Ian
- 5,704
- 6
- 40
- 72
0
votes
1 answer
Get parent Enumeration of Value typetag
I have a Type instance that refers to the Value of a specific Enumeration.
Is there any way to get the Type or Symbol of the parent enum? In other words, if I have typeOf[SomeEnumeration.Value] how can I obtain typeOf[SomeEnumeration]?
I know this…

Ian
- 5,704
- 6
- 40
- 72
0
votes
1 answer
Can Scala reflection get you the list of type aliases defined in a class?
The situation I'm facing is one where I need to instantiate a class by name, but that class is actually a scala type alias defined in an object (a package object actually). I have figured out many piece of what I need for this, but I can't find a…

Dave DeCaprio
- 2,051
- 17
- 31
0
votes
2 answers
How to extract types from tuple type?
I have a code
case class MyTypeTag[T] ()
def getTypeTags[TT <: Product : TypeTag] = {
val subtypesTags: List[MyTypeTag[Option[_]] = ???
sybtypesTags
}
val res = getTypeTags[(Int, String, Boolean)]
// res = MyTypeTag[Option[Int]] ::…

Dmitry Reutov
- 2,995
- 1
- 5
- 20
0
votes
0 answers
How to use `ClassTag` and type comparison operator, `<:` at the same time?
I have the following class defined,
class FixedLengthQueue[T<:Hashable](maxLength: Int) {
private val _outdated = ArrayBuffer.empty[T]
def outdated: Array[T] = {
val result = _outdated.toArray[T]
_outdated.clear()
result
…

Max Wong
- 694
- 10
- 18
0
votes
0 answers
Why is a type of the member of the object different in a function?
Code below produces following result:
as member: nested: AnyRef{def x: Int; def x_=(x$1: Int): Unit}
as local: nested: Object
(Tested with Scala 2.12.12 and Scala 2.12.3)
Can someone explain why?
object Main extends App {
def getNestedType(m:…

Suma
- 33,181
- 16
- 123
- 191
0
votes
1 answer
Find out the type arguments for a type constructor knowing the type arguments of the type constructor it extends
Let X be a type constructor with type parameters A1, A2, ..., An. For example Option[A] and Function1[A1, A2].
Let X[T1, T2, ..., Tn] be the type resulting of applying the type constructor X to the concrete type argument T1, T2, ... Tn. For example…

Readren
- 994
- 1
- 10
- 18
0
votes
2 answers
In a scala macro, how to get the full name that a class will have at runtime?
The intention is to get at run-time some info of particular classes that is available only at compile-time.
My approach was to generate the info at compile time with a macro that expands to a map that contains the info indexed by the runtime class…

Readren
- 994
- 1
- 10
- 18
0
votes
1 answer
Play framework and reading a scala annotation
I am struggling to get a value from a scala annotation in a Play controller method.
I defined a class for the annotation:
case class Auth(perm: String) extends scala.annotation.StaticAnnotation
Then I am reading it in one of the Play's…

synthetic
- 798
- 1
- 7
- 20
0
votes
1 answer
Troubles with getting case class fields via reflection
I have a scala code: trait model and its implementation case class Category with custom annotation which i wish to read later
import scala.annotation.StaticAnnotation
class ExtraFields() extends StaticAnnotation
trait Model {}
case class…

Dmitry Reutov
- 2,995
- 1
- 5
- 20
0
votes
1 answer
Invoke private method in arbitrary scala object
Let's say I have a Scala object:
object SomeObject {
private def someMethod(msg: String): Unit = println(msg)
}
I can invoke someMethod with the following code:
import scala.reflect.runtime.{universe => ru}
import scala.reflect.ClassTag
def…

ishovelwell
- 13
- 4
0
votes
1 answer
Using reflections to access methods in Amazon Deequ
I plan on creating a user config file that I will later parse in order to run some checks from Amazon Deequ. I want to be able to pass the string names from the config file to get the methods; however, in my attempts to do so, I keep hitting…

dustin
- 4,309
- 12
- 57
- 79
0
votes
1 answer
Facing issue while using reflection class concept in scala
I have one main class like this:
class Test {
def exe(first:String, second:String, task:String):String = {
task match {
case "A" => {
val obj = new A(first)
obj.defineSecond(second)
}
case "B" => {
…

Sunny Arora
- 33
- 3
0
votes
1 answer
How to pass into generic type using a Symbol or Type object into a generic typed function?
In Scala, is it possible to pass a type derived from a Symbol or Type object into a generic typed function? For example:
case class Address(street: String, city: String, state: String, zipCode: String)
case class Person(name: String, age: Int,…

code
- 5,294
- 16
- 62
- 113
0
votes
1 answer
How to determine if a class is a subclass of a parent class or trait?
In Scala, how can we determine if a class is a subclass of a parent class or a trait? For example:
trait MyTrait
class MyParentClass()
class MyOtherParentClass()
case class MySubClass() extends MyParentClass with MyTrait
case class…

code
- 5,294
- 16
- 62
- 113