【发布时间】:2010-04-14 10:14:20
【问题描述】:
通过java反射如何检查方法名是否在camelCase中? 例如
import java.lang.reflect.*;
public class TestClass {
private int simpleMethod(
Object p, int x) throws NullPointerException
{
if (p == null)
throw new NullPointerException();
return x;
}
public static void main(String args[])
{
try {
Class cls = Class.forName("method1");
Method methlist[]
= cls.getDeclaredMethods();
for (int i = 0; i < methlist.length;
i++) {
Method m = methlist[i];
System.out.println("name= " + m.getName());
}
}
catch (Throwable e) {
System.err.println(e);
}
}
}
这里我得到了方法名称 simpleMethod 和 main 我必须检查这些名字是否用驼峰命名。
【问题讨论】:
-
驼峰式。喜欢这种表达方式。
标签: java reflection