score:4
Accepted answer
Could this answer help you?
Here is an example for scalaVersion := "2.11.1"
import scala.reflect.runtime.{universe => u}
def companionMembers(clazzTag: scala.reflect.ClassTag[_]): u.MemberScope = {
val runtimeClass = clazzTag.runtimeClass
val rootMirror = u.runtimeMirror(runtimeClass.getClassLoader)
val classSymbol = rootMirror.classSymbol(runtimeClass)
// get the companion here
classSymbol.companion.typeSignature.members
}
case class MyClass(value: Int)
val applyMethods =
companionMembers(scala.reflect.classTag[MyClass])
.filter { m => m.isMethod && m.name.toString == "apply"}
println(applyMethods)
prints
Scope{
case def apply(value: scala.Int): MyClass
}
Source: stackoverflow.com
Related Query
- In scala, use reflection on a case class classtag to find the companion object's apply method
- Scala Case Class Companion Objects - Conflict on the type name
- Scala spark: how to use dataset for a case class with the schema has snake_case?
- Is it possible to use reflection to find the actual type of a field declared to be a Scala Enumeration subtype?
- what is the use case for scala List's companion function returning GenericCompanion?
- what is the use of [] these brackets in case class before parameter list in scala
- Use scala reflection to initiate class with internal objects
- Do two copies of a case class use twice the memory when only one property is changed, or does Scala reuse immutable values on copy to save memory?
- How can I use Scala reflection to find the self type traits?
- How to get around the Scala case class limit of 22 fields?
- Why do case class companion objects extend FunctionN?
- Scala 2.10 reflection, how do I extract the field values from a case class, i.e. field list from case class
- Instantiate a Scala class from Java, and use the default parameters of the constructor
- Reflection on a Scala case class
- Obtaining the full info about fields of the case class in Scala
- How do I create an explicit companion object for a case class which behaves identically to the replaced compiler provided implicit companion object?
- scala case class put methods in companion object?
- In Scala is there a way to reference the Companion Object from within an instance of a Case Class?
- How to check which parameters of case class have default value using scala reflection 2.10
- Scala case class ignoring import in the Spark shell
- Get the companion object instance of a inner modul with the Scala reflection API
- How to convert the Scala case class definition to Haskell?
- scala syntax to match on multiple case class types without decomposing the case class
- Scala what is the difference between defining a method in the class instead on the companion object
- Scala Reflection to update a case class val
- how to use special character in scala case class
- An object extends its companion case class in Scala
- Scala : How to use Global Config case class across application
- Companion object in Scala isn't associating itself with case class
- Getting the parameters of a case class through Reflection
More Query from same tag
- How can I force spark/hadoop to ignore the .gz extension on a file and read it as uncompressed plain text?
- Obtaining array element in Scala works only with explicit apply method
- "spark.memory.fraction" seems to have no effect
- Empty output for Watermarked Aggregation Query in Append Mode
- ERROR com.websudos.phantom - Batch too large
- Name object in Scala List constructor
- How can I get Intellij to stop underlining my scala code?
- How to parse Json data returned from a HTTP request in scala
- Variance under Inheritance scala
- SBT: Where does compiler-interface go once it is built?
- Sampling without Replacement using Scala and Breeze
- Break out of loop in scala while iterating on list
- Expand type class operations on elements using macros
- serialization (pickling / marshalling) in scala?
- Running Scala function from command line
- Make sure query is executed or not with Anorm
- scala circe encoders/decoders for an abstract class with case classes
- Maintain order in .groupBy() operation of Scala collection
- Alternative to Akka for handling tasks sequentially
- Flink watermark is negative
- How do I transform my Scala XML object (of class Elem) to HTML using XSLT?
- Getting Bootstrap broker ip:9092 disconnected error from kafka spout
- Swap constructor arguments
- Get content from anyContent as Json
- How do I configure Scala Breeze to use log4j or slf4j
- MongoDB update a document when exists already with ReactiveMongo
- Scala data structures: chain of operations (such as mapValues, filter ...) and intermediate results
- Running and downloading Apache Spark without Scala Compilers
- How can I process a file uploaded through an HTML form in Spray/Scala/Java?
- Find a record with max value in a group