动态加载类并调用Java中的方法 [英] Dynamically load a Class and invoke a method in Java
本文介绍了动态加载类并调用Java中的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我说我想在Java中动态加载一个类并称其为start()
(没有参数)方法:
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?
推荐答案
对我很好.
如果您正在做很多与反射相关的代码,则可以查看Apache Beanutils 或Apache OGNL 或类似的东西.
If you're doing a lot of reflection-related code you might look at Apache Beanutils or Apache OGNL or something similar.
这篇关于动态加载类并调用Java中的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文