Here you can find the source of getMethod(final Class> target, final String name, final Class>... parameters)
Parameter | Description |
---|---|
target | Target class that contains method. |
name | Method name. |
parameters | Method parameters. |
public static Method getMethod(final Class<?> target, final String name, final Class<?>... parameters)
//package com.java2s; /* See LICENSE for licensing and NOTICE for copyright. */ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; public class Main { /** Method cache. */ private static final Map<String, Method> METHOD_CACHE = new HashMap<>(); /**// w w w . j a v a 2 s . c o m * Gets the method defined on the target class. The method is cached to speed * up subsequent lookups. * * @param target Target class that contains method. * @param name Method name. * @param parameters Method parameters. * * @return Method if found, otherwise null. */ public static Method getMethod(final Class<?> target, final String name, final Class<?>... parameters) { final String key = target.getName() + '.' + name; Method method = METHOD_CACHE.get(key); if (method != null) { return method; } try { method = target.getMethod(name, parameters); METHOD_CACHE.put(key, method); return method; } catch (NoSuchMethodException e) { return null; } } }