/** true iff the initial N args match the corresponding types */ public static boolean typeMatches(Object arg, Class<?> parameterType, Optional<? extends TypeCoercer> coercer) { if (parameterType.isPrimitive() && arg == null) return false; if (arg == null) return true; if (Boxing.boxedType(parameterType).isInstance(arg)) return true; if (coercer.isPresent() && coercer.get().tryCoerce(arg, parameterType).isPresent()) return true; return false; }
@Test public static void testIntPrimitiveAndBoxed() { Assert.assertEquals(Integer.TYPE.getName(), "int"); Class<?> t = Boxing.getPrimitiveType("int").get(); Assert.assertEquals(t, Integer.TYPE); Class<?> bt = Boxing.boxedType(t); Assert.assertEquals(bt, Integer.class); }
boolean varargsMatch = true; for (int i=parameterTypes.length-1; i<argsArray.length; i++) { if (!Boxing.boxedType(varargType).isInstance(argsArray[i]) || (varargType.isPrimitive() && argsArray[i]==null)) { varargsMatch = false;