【发布时间】:2013-10-17 05:23:25
【问题描述】:
如何获取我在 java 中的 Class 中拥有的所有 Methods() 的列表(名称)?
例如
public class helloworld {
public static void main() {
...
}
public static void method() {
...
}
public static void anothermethod() {
...
}
}
结果是:
method
anothermethod
有可能吗?提前致谢。
【问题讨论】:
-
Reflection 会为你做到这一点。
-
是的,有可能,搜索反射。
-
请不要
helloworld,而是HelloWorld。不是anothermethod,而是anotherMethod()。遵循 Java 命名约定。 -
扩展 Zavior 之前所说的内容:this 文档链接。
-
你看过 java.lang.Class 的规范了吗??