Here you can find the source of getMethodNoArgs(final Class> objClass, final String methodName, final Class>... returnTypePreference)
Parameter | Description |
---|---|
objClass | a parameter |
methodName | a parameter |
returnTypePreference | a parameter |
public static Method getMethodNoArgs(final Class<?> objClass, final String methodName, final Class<?>... returnTypePreference)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; public class Main { /**/* ww w. jav a2 s . c om*/ * Direct getMethod attempt. * @param objClass * @param methodName * @param returnTypePreference * @return */ public static Method getMethodNoArgs(final Class<?> objClass, final String methodName, final Class<?>... returnTypePreference) { try { final Method methodFound = objClass.getMethod(methodName); if (methodFound != null) { if (returnTypePreference == null || returnTypePreference.length == 0) { return methodFound; } final Class<?> returnType = methodFound.getReturnType(); for (int i = 0; i < returnTypePreference.length; i++) { if (returnType == returnTypePreference[i]) { return methodFound; } } } } catch (SecurityException e) { } catch (NoSuchMethodException e) { } return null; } /** * Fail-safe getMethod. * @param clazz * @param methodName * @param arguments * @return null in case of errors. */ public static Method getMethod(Class<?> clazz, String methodName, Class<?>... arguments) { try { return clazz.getMethod(methodName, arguments); } catch (NoSuchMethodException e) { } catch (SecurityException e) { } return null; } /** * Get a method matching one of the declared argument specifications. * @param clazz * @param methodName * @param argumentLists * @return The first matching method (given order). */ public static Method getMethod(Class<?> clazz, String methodName, Class<?>[]... argumentLists) { Method method = null; for (Class<?>[] arguments : argumentLists) { method = getMethod(clazz, methodName, arguments); if (method != null) { return method; } } return null; } }