Search This Blog

Tuesday, April 13, 2010

check for naming convention in java.

Programmer Question

through java reflection how to check that method name is in camelCase?
e.g.



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);
}
}
}


here i am getting method names simpleMethod and main
i have to check that these names are in camelCase.



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails