Java Utililty Methods Method from Class

List of utility methods to do Method from Class

  1. HOME
  2. Java
  3. M
  4. Method from Class

Description

The list of methods to do Method from Class are organized into topic(s).

Method

boolean existsMethod(final String clazz, final String name, final Class[] parameterTypes)
Analyze if a class or one of its super classes contains a given method.
Class c;
try {
 c = Class.forName(clazz);
} catch (ClassNotFoundException e) {
 return false;
return existsMethod(c, name, parameterTypes);
Method findMethod(Class javaClass, String methodName, Class[] methodParameterTypes)
Finding a method within a class potentially has to navigate through it's superclasses to eventually find the method.
try {
 return javaClass.getDeclaredMethod(methodName, methodParameterTypes);
} catch (NoSuchMethodException ex) {
 Class superclass = javaClass.getSuperclass();
 if (superclass == null) {
 throw ex;
 } else {
 try {
...
Method findMethod(Class c, String name, Class params[])
find Method
Method methods[] = findMethods(c);
if (methods == null)
 return null;
for (int i = 0; i < methods.length; i++) {
 if (methods[i].getName().equals(name)) {
 Class<?> methodParams[] = methods[i].getParameterTypes();
 if (methodParams == null)
 if (params == null || params.length == 0)
...
Method findMethod(Method m, Class c)
find Method
String name = m.getName();
Class<?> params[] = new Class<?>[0];
try {
 return c.getMethod(name, params);
} catch (Throwable th) {
 return null;
Method[] findMethods(Class c)
find Methods
Method methods[] = (Method[]) objectMethods.get(c);
if (methods != null)
 return methods;
methods = c.getMethods();
objectMethods.put(c, methods);
return methods;
Set getAllMethodsWithAnnotation(String packageName, Class annotation)
get All Methods With Annotation
Set<Method> methods = new HashSet<Method>();
try {
 for (Class<?> cls : getClasses(packageName)) {
 for (Method method : cls.getMethods()) {
 if (hasAnnotation(method, annotation)) {
 methods.add(method);
} catch (SecurityException e) {
 System.err.println("ClassUtil.getAllMethods: " + e.getMessage());
} catch (IOException e) {
 System.err.println("ClassUtil.getAllMethods: " + e.getMessage());
return methods;
Method getDeclaredMethod(final Class clazz, final String methodName, final Class[] methodParameterTypes)
Return a method on a given class with the given method name and parameter types.
return clazz.getDeclaredMethod(methodName, methodParameterTypes);
Method getMethod(Class type, Method m)
get Method
if (m == null || Modifier.isPublic(type.getModifiers())) {
 return m;
Class<?>[] inf = type.getInterfaces();
Method mp = null;
for (int i = 0; i < inf.length; i++) {
 try {
 mp = inf[i].getMethod(m.getName(), m.getParameterTypes());
...
Method getMethod(final Class javaClass, final String methodName, final Class[] methodParameterTypes, final boolean shouldSetAccessible)
Get a method declared in the given class.
Method method = findMethod(javaClass, methodName, methodParameterTypes);
if (shouldSetAccessible) {
 method.setAccessible(true);
return method;
Method[] getMethods(final Class clazz)
Get the list of methods in a class.
return clazz.getMethods();


AltStyle によって変換されたページ (->オリジナル) /