How to call the object method (not class method) using reflection in scala -
this question has answer here:
i'd call object main method using reflection in scala. did not works, following 2 lines of code through exception not create object using reflection.
val clazz = class.forname(job.runnerclass) val runnerclass = clazz.newinstance()
first have use $ @ end of class name, because scala objects end $. can find object instance in field called module$
val class = class.forname(name) val objectinstance = class.getfield("module$").get(class).asinstanceof[yourclasstype]
Comments
Post a Comment