ReflectionUtils { public static Method getMethod(ClassLoader cl, Class<?> clazz, String methodName, Collection<String> parameterTypes) throws ReflectiveOperationException { boolean hasPrimitive = false; Class<?>[] methodParameters = new Class<?> [parameterTypes.size()]; Class<?>[] primitiveParameters = new Class<?> [parameterTypes.size()]; Iterator<String> iter = parameterTypes.iterator(); int i = 0; while (iter.hasNext()) { String parameter = iter.next(); if (!parameter.contains(".")) { parameter = "java.lang." + parameter; } Class<?> parameterClass = cl.loadClass(parameter); methodParameters[i] = parameterClass; Class<?> primitive = wrappers2Primitive.get(parameterClass); if (primitive != null) { primitiveParameters[i] = primitive; hasPrimitive = true; } else { primitiveParameters[i] = parameterClass; } i++; } try { return clazz.getMethod(methodName, methodParameters); } catch (NoSuchMethodException ex) { if (hasPrimitive) { try { return clazz.getMethod(methodName,primitiveParameters); } catch (NoSuchMethodException ex2) { logger.warn("Unable to find method {} with primitive arguments {}", methodName, primitiveParameters); } } throw ex; } } private  ReflectionUtils(); static boolean isWrapper(Class<?> clazz); static Class<?> getPrimitive(Class<?> clazz); static Method getMethod(ClassLoader cl,
                  Class<?> clazz,
                  String methodName,
                  Collection<String> parameterTypes);  }
@Test public void testGetMethod() throws ReflectiveOperationException { ServiceExample instance = new ServiceExample(); Method m = ReflectionUtils .getMethod( Thread.currentThread().getContextClassLoader(), ServiceExample.class, "primitiveType", Arrays.asList("String", "Integer")); assertEquals(Integer.valueOf(2), m.invoke(instance, "pepe", 2)); m = ReflectionUtils .getMethod( Thread.currentThread().getContextClassLoader(), ServiceExample.class, "primitiveType", Arrays.asList("String", "Float")); assertEquals(Float.valueOf(2.0f), m.invoke(instance, "pepe", 2.0f)); }