def companion[T](name : String)(implicit man: Manifest[T]) : T =
Class.forName(name + "$").getField("MODULE$").get(man.erasure).asInstanceOf[T]
val result = companion[SomeTrait]("SomeObject").someMethod
More Related Contents:
- Scala: How do I dynamically instantiate an object and invoke a method using reflection?
- Difference between object and class in Scala
- Generating a class from string and instantiating it in Scala 2.10
- Get companion object instance with new Scala reflection API
- Finding type parameters via reflection in Scala 2.10?
- How does Rust implement reflection?
- Instantiating immutable paired objects
- I want to get the type of a variable at runtime
- val and object inside a scala class?
- Pattern matching on generic type in Scala
- Getting method parameter names
- How do I access default parameter values via Scala reflection?
- Go reflection with interface embedded in struct – how to detect “real” functions?
- How can I get the list of a columns in a table for a SQLite database?
- How to get ClassTag form TypeTag, or both at same time?
- How to access parameter list of case class in a dotty macro
- Get a TypeTag from a Type?
- How to get type of the module in F#
- Creating a method definition tree from a method symbol and a body
- Scala 2.10 reflection, how do I extract the field values from a case class, i.e. field list from case class
- Test for existence of nested JavaScript object key
- How to define “type disjunction” (union types)?
- How to access the first property of a Javascript object?
- Referring to the null object in Python
- What is the motivation for Scala assignment evaluating to Unit rather than the value assigned?
- How to display image with JavaScript?
- What is the JavaScript equivalent of var_dump or print_r in PHP? [duplicate]
- PHP 5 Reflection API performance
- Java casting “.class”-operator used on a generic type, e.g. List, to “Class
- How is this case class match pattern working?