I'm trying to use getMethod()
public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
What does that the second argument mean? For example, what should i do if i have two parameters to set?
I'm trying to use getMethod()
public Method getMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
What does that the second argument mean? For example, what should i do if i have two parameters to set?
In Java, you identify methods by name AND signature meaning order, count and types of method parameters. That is what the second argument stand for.
Method overloading means you have at least two (or more) methods with same name, but different signatures. Using Java reflection code, you have to specify the types of parameters. This is done via varargs-argument, for example:
Method m = getMethod("xyz", Integer.class, String.class);
refers to:
{modifiers} {return type} xyz(Integer arg1, String arg2);
The second argument specifies a variable argument. This means that you can supply any list of arguments of the specified type. When you access it in the method body it's just an array. It's just syntactic sugar.
final Method method = clazz.getMethod("methodName", String.class, Integer.class);