Home How to pass Dynamic class name inside of the Class.forName()?
Reply: 0

How to pass Dynamic class name inside of the Class.forName()?

user958
1#
user958 Published in April 23, 2018, 9:40 am

I have to send class name inside Class.forName(myclass) but it does not work because my class names are fully dynamic values. when i pass like this Class.forName("com.example.myapp.myclassname") its working fine. but when i try to pass the class name as dynamic one it does not working. i get class name from db and stored in string variable and pass that variable into forName() method but its always return Class not found error.

what i tried,

classDefinition = Class.forName("com.example.MyPack.MyApp.MyClass"); // its working fine

but it does not working when i pass the string inside the forName(string), string is hold the class path(fully qualified value)

function demo(String className){

    String dynamicClass = className;
    classDefinition = Class.forName(dynamicClass );
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.425268 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO