@Test public void unboundTypesShouldMatchWithObject() throws NoSuchFieldException { Type t = Generic.class.getDeclaredField("t").getGenericType(); assertTrue(match(t, Object.class, true)); assertTrue(match(t, Object.class, false)); }
public final static boolean match(Type type, Type oType, boolean strictMatch) { if (type == null || oType == null) return type == null && oType == null; Class<?> clazz = getRawClass(type); Class<?> oClazz = getRawClass(oType); boolean match = strictMatch ? oClazz.equals(clazz) : oClazz.isAssignableFrom(clazz); if (Object.class.equals(clazz)) return match; if (Object.class.equals(oClazz) && !strictMatch) return match; if (clazz.isArray() && !oClazz.isArray()) return match; Type[] types = getTypes(type); Type[] oTypes = getTypes(oType); match = match && (types.length == oTypes.length || types.length == 0); for (int i = 0; i < types.length && match; i++) match = match(types[i], oTypes[i], strictMatch); return match; }
TypeUtil { public final static boolean match(Type type, Type oType, boolean strictMatch) { if (type == null || oType == null) return type == null && oType == null; Class<?> clazz = getRawClass(type); Class<?> oClazz = getRawClass(oType); boolean match = strictMatch ? oClazz.equals(clazz) : oClazz.isAssignableFrom(clazz); if (Object.class.equals(clazz)) return match; if (Object.class.equals(oClazz) && !strictMatch) return match; if (clazz.isArray() && !oClazz.isArray()) return match; Type[] types = getTypes(type); Type[] oTypes = getTypes(oType); match = match && (types.length == oTypes.length || types.length == 0); for (int i = 0; i < types.length && match; i++) match = match(types[i], oTypes[i], strictMatch); return match; } }
TypeUtil { public final static boolean match(Type type, Type oType, boolean strictMatch) { if (type == null || oType == null) return type == null && oType == null; Class<?> clazz = getRawClass(type); Class<?> oClazz = getRawClass(oType); boolean match = strictMatch ? oClazz.equals(clazz) : oClazz.isAssignableFrom(clazz); if (Object.class.equals(clazz)) return match; if (Object.class.equals(oClazz) && !strictMatch) return match; if (clazz.isArray() && !oClazz.isArray()) return match; Type[] types = getTypes(type); Type[] oTypes = getTypes(oType); match = match && (types.length == oTypes.length || types.length == 0); for (int i = 0; i < types.length && match; i++) match = match(types[i], oTypes[i], strictMatch); return match; }  }
TypeUtil { public final static boolean match(Type type, Type oType, boolean strictMatch) { if (type == null || oType == null) return type == null && oType == null; Class<?> clazz = getRawClass(type); Class<?> oClazz = getRawClass(oType); boolean match = strictMatch ? oClazz.equals(clazz) : oClazz.isAssignableFrom(clazz); if (Object.class.equals(clazz)) return match; if (Object.class.equals(oClazz) && !strictMatch) return match; if (clazz.isArray() && !oClazz.isArray()) return match; Type[] types = getTypes(type); Type[] oTypes = getTypes(oType); match = match && (types.length == oTypes.length || types.length == 0); for (int i = 0; i < types.length && match; i++) match = match(types[i], oTypes[i], strictMatch); return match; }  final static Class<?> wrap(Class<?> clazz); final static Type expandType(final Type type, final Type rootType); final static Type lookupGenericType(Class<?> ofClass, Class<?> inClass); final static Class<?> getRawClass(Type type); final static Type getCollectionType(Type type); final static Type resolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> inClass); final static boolean match(Type type, Type oType, boolean strictMatch); final static Type typeOf(int parameterIdx, Type fromType); }
TypeUtil { public final static boolean match(Type type, Type oType, boolean strictMatch) { if (type == null || oType == null) return type == null && oType == null; Class<?> clazz = getRawClass(type); Class<?> oClazz = getRawClass(oType); boolean match = strictMatch ? oClazz.equals(clazz) : oClazz.isAssignableFrom(clazz); if (Object.class.equals(clazz)) return match; if (Object.class.equals(oClazz) && !strictMatch) return match; if (clazz.isArray() && !oClazz.isArray()) return match; Type[] types = getTypes(type); Type[] oTypes = getTypes(oType); match = match && (types.length == oTypes.length || types.length == 0); for (int i = 0; i < types.length && match; i++) match = match(types[i], oTypes[i], strictMatch); return match; }  final static Class<?> wrap(Class<?> clazz); final static Type expandType(final Type type, final Type rootType); final static Type lookupGenericType(Class<?> ofClass, Class<?> inClass); final static Class<?> getRawClass(Type type); final static Type getCollectionType(Type type); final static Type resolveTypeVariable(TypeVariable<? extends GenericDeclaration> type, Class<?> inClass); final static boolean match(Type type, Type oType, boolean strictMatch); final static Type typeOf(int parameterIdx, Type fromType);  }