コード例 #1
0
  @Test
  public void get_generic_type_of_a_field() throws Exception {
    Field field = Dummy.class.getDeclaredField("stringListField");
    ParameterizedType type = (ParameterizedType) field.getGenericType();

    assertEquals(List.class, type.getRawType());
    assertArrayEquals(new Type[] {String.class}, type.getActualTypeArguments());
    assertEquals(null, type.getOwnerType());
  }
コード例 #2
0
  @Test
  public void get_generic_type_of_interface_method_parameters() throws Exception {
    Method method = Interface.class.getDeclaredMethod("stringListMethod", List.class);
    Type[] types = method.getGenericParameterTypes();
    ParameterizedType type = (ParameterizedType) types[0];

    assertEquals(List.class, type.getRawType());
    assertArrayEquals(new Type[] {String.class}, type.getActualTypeArguments());
    assertEquals(null, type.getOwnerType());
  }