Home > other >  Scala in reflection classes, how to find the constructor, initialize the instance objects
Scala in reflection classes, how to find the constructor, initialize the instance objects

Time:09-22

 
The object classReflect extends App {
Val builder="Leo. Makukin. Scalatest. TestObject"
Val fs="3"
Val obj=LogClassLoader. FindClass (builder)
Val paramsType=Array (Class [_]] (classOf (Integer), classOf [String], classOf [Map [String, String]])
Val con=obj. GetDeclaredConstructor (paramsType: _ *)
Con. NewInstance (new Integer (4), "SDF", the Map [String, String] ())

}

A case class TestObject (c: Int, a: String, b: Map [String, String])

This program when the reflection classes, complains, has a friend ever write a similar procedure, to help have a look
  • Related