Code example for Constructor

Methods: getGenericParameterTypes

0
    public void testConstructorGenericType() throws Exception { 
        Class<? extends ConstructorGenericType> clazz = ConstructorGenericType.class;
        TypeVariable<Class> typeVariable = getTypeParameter(clazz);
        Constructor<?> constructor = clazz.getDeclaredConstructor(Object.class);
        Type[] genericParameterTypes = constructor.getGenericParameterTypes();
        assertLenghtOne(genericParameterTypes);
        Type parameterType = genericParameterTypes[0];
 
        assertEquals(typeVariable, parameterType);
    } 
    @SuppressWarnings("unchecked") 
    public void testStaticMethodGenericType() throws Exception { 
        Class<? extends GenericType> clazz = GenericType.class;
        TypeVariable<Class> typeVariable = getTypeParameter(clazz);
 
        Method method = clazz.getDeclaredMethod("staticMethodGenericType", Object.class);
        Type[] genericParameterTypes = method.getGenericParameterTypes();
        assertLenghtOne(genericParameterTypes);
        Type parameterType = genericParameterTypes[0];
        assertNotEquals(typeVariable, parameterType);
        assertInstanceOf(TypeVariable.class, parameterType);