Monday, June 22, 2020

Scala : Reflections

Scala : Reflections 


used to Convert the input string into Scala object.
Eg :
In below example class name "testsubclass" is a string in the main object Which is converted into scala object.

class testsubclass { 
def hi:String=return ("newx") 
}
 
object Test{ 
def main((args: Array[String]):{
val x:Any=(Class.forName("testsubclass").newInstance() println(x.asInstanceOf[{def hi:String}]).hi) 
//method declared and method name called should match 
} }




No comments:

Post a Comment