You could try ((ParameterizedType)f.getGenericType()).getActualTypeArguments() to get a Type[] array which in your case should have 1 element: X.class. Note that this only works in cases where you can use reflection (i.e. not for local variables) and if the types are boundaries you'd need to handle it differently. Also ,you'd need to check if getGenericType() really returns a ParameterizedType.
Other methods you might want to look into:
- for classes use getTypeParameters(), this would return an empty array for non generic classes
- for method return types use getGenericReturnType()
- for method and constructor parameters use getGenericParameterTypes(), this would return an empty array for no-arg methods
Some types/interfaces they might return:
- actual classes for raw types
- ParameterizedTypefor generic fields, parameters and return types
- TypeVariablefor generic type parameters without wildcards
- WildcardTypefor generic type parameters with a wildcard