From what I understand, methods can be dynamically called if both the method name and list of parameter types are provided (see below). However, is there a way to dynamically call a method without specifying parameter types or alternatively providing un/bounded generic class types? If yes, explanations/examples would be appreciated. Thanks.
Class<?>[] paramTypes = {String.class};
Method m = original.getClass().getMethod(methodName, paramTypes);
m.invoke(original, value);
There is a solution since Java 1.4,
Statement
andExpression
of the beans package. For your invocation, not evaluating return values, you can useSince it has to figure out even more than the direct Reflection usage, you can expect the performance to be even worse than directly using Reflection.
Further, it is restricted to
public
APIs.