Here you can find the source of getMethod(Object instance, String methodName, Class>... argsClass)
public static Optional<Method> getMethod(Object instance, String methodName, Class<?>... argsClass)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; import java.util.Optional; public class Main { public static Optional<Method> getMethod(Class<?> clazz, String methodName, Class<?>... argsClass) { try {/*from w w w. j av a 2s. c o m*/ return Optional.of(clazz.getMethod(methodName, argsClass)); } catch (NoSuchMethodException | SecurityException e) { e.printStackTrace(); } return Optional.empty(); } public static Optional<Method> getMethod(Object instance, String methodName, Class<?>... argsClass) { try { return Optional.of(instance.getClass().getMethod(methodName, argsClass)); } catch (NoSuchMethodException | SecurityException e) { e.printStackTrace(); } return Optional.empty(); } }