Java Reflection Method Get from Object getMethod(Object instance, String methodName, Class... argsClass)

Here you can find the source of getMethod(Object instance, String methodName, Class... argsClass)

Description

get Method

License

Apache License

Declaration

public static Optional<Method> getMethod(Object instance, String methodName, Class<?>... argsClass) 

Method Source Code

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

Related

  1. getMethod(final Object object, final String methodName, final Object... arguments)
  2. getMethod(final Object object, String methodName, final Class[] argTypes)
  3. getMethod(final Object target, final String methodName, final Class... argumentTypes)
  4. getMethod(final String methodName, final Object obj, final Class... argTypes)
  5. getMethod(Object bean, String propertyName)
  6. getMethod(Object instance, String methodName, Class[] parameters)
  7. getMethod(Object o, String methodName)
  8. getMethod(Object o, String methodName, Class[] args)
  9. getMethod(Object o, String methodName, Class[] paramTypes)