Lets say i want to dynamically load a class in java and call it's start()
(has no params) method:
Class<?> c = Class.forName("AbuseMe");
c.getMethod("start").invoke(c.newInstance());
Would this be a good/safe way to do it?
Lets say i want to dynamically load a class in java and call it's start()
(has no params) method:
Class<?> c = Class.forName("AbuseMe");
c.getMethod("start").invoke(c.newInstance());
Would this be a good/safe way to do it?
Looks good to me.
If you're doing a lot of reflection-related code you might look at Apache Beanutils or Apache OGNL or something similar.
Reflection is a very useful approach to deal with the Java class at runtime, it can be use to load the Java class, call its methods or analysis the class at runtime.
Try this example.
This will surely help you.
How To Use Reflection To Call Java Method At Runtime
Thanks