| 658 | |
| 659 | |
| 660 | public static Object callDynamically(Object obj, Object methodName, Object[] args) { |
| 661 | if (args == null) args = new Object[]{}; |
| 662 | |
| 663 | String name = (String) methodName; |
| 664 | Method m = findMethod(obj.getClass(), name, args.length); |
| 665 | |
| 666 | try { |
| 667 | m.setAccessible(true); |
| 668 | |
| 669 | Object[] invokeArgs = adaptForVarArgs(m, args); |
| 670 | coerceArgs(m, invokeArgs); |
| 671 | |
| 672 | return m.invoke(obj, invokeArgs); |
| 673 | |
| 674 | } catch (Exception e) { |
| 675 | throw new RuntimeException(e); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * Coerce arguments to match the method's parameter types. |