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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -