Here you can find the source of getMethodIfAvailable(Class> clazz, String methodName, Class>... paramTypes)
null
).
Parameter | Description |
---|---|
clazz | the clazz to analyze |
methodName | the name of the method |
paramTypes | the parameter types of the method |
null
if not found
public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes)
//package com.java2s; import java.lang.reflect.Method; public class Main { /**/*from ww w . j a va 2 s. com*/ * Determine whether the given class has a method with the given signature, * and return it if available (else return <code>null</code>). * <p>Essentially translates <code>NoSuchMethodException</code> to <code>null</code>. * @param clazz the clazz to analyze * @param methodName the name of the method * @param paramTypes the parameter types of the method * @return the method, or <code>null</code> if not found * @see java.lang.Class#getMethod */ public static Method getMethodIfAvailable(Class<?> clazz, String methodName, Class<?>... paramTypes) { if (clazz == null) { throw new IllegalArgumentException("Class must not be null"); } if (methodName == null) { throw new IllegalArgumentException("Method name must not be null"); } try { return clazz.getMethod(methodName, paramTypes); } catch (NoSuchMethodException ex) { return null; } } }