@Test public void testgeneric3() throws SecurityException, NoSuchMethodException { System.out.println("==== testgeneric3 ===="); Type c1 = new TypeToken<GenericTypeTemplateTest<java.sql.Date>>() {}.getType(); // 得到泛型类的实例类型。 Type c = GenericUtils.newGenericType(GenericTypeTemplateTest.class, java.sql.Date.class); ClassEx cw = new ClassEx(c); MethodEx method = cw.getFirstMethodByName("test1"); Type type = method.getGenericReturnType(); Type result = GenericUtils.getBoundType(type, cw); System.out.println("result:" + result); // Type type=method.getGenericReturnType(); // ParameterizedType pType=(ParameterizedType)type; // // // // System.out.println(pType.getActualTypeArguments()[0]); // WildcardType wt=(WildcardType)pType.getActualTypeArguments()[0]; // TypeVariable upper=(TypeVariable)wt.getUpperBounds()[0]; // Type context=cw.getImplType(upper); // System.out.println(context); // // Type result=GenericUtils.newGenericType((Class<?>)pType.getRawType(), context); // System.out.println(result); }
@Test public void testgeneric5() throws SecurityException, NoSuchMethodException { System.out.println("==== testgeneric5 ===="); Type map1 = GenericUtils.newMapType(String.class, String.class); Type map2 = GenericUtils.newMapType(String.class, Object.class); Type map3 = Map.class; Type c = GenericUtils.newGenericType(GenericTypeTemplateTest.class, java.sql.Date.class); ClassEx cw = new ClassEx(c); MethodEx method = cw.getFirstMethodByName("test4"); System.out.println(map1.equals(method.getGenericParameterTypes()[0])); System.out.println(map2.equals(method.getGenericReturnType())); }