Understanding Java Type Interface and Its Subinterfaces in Reflection
This article explains the Java reflection Type interface, its subinterfaces ParameterizedType, TypeVariable, GenericArrayType, and WildcardType, their methods and usage, and why generic‑related types are represented separately from Class.
Java's Type interface is the root of all type representations used in reflection, covering raw types, parameterized types, array types, type variables, and primitive types.
Its known subinterfaces are ParameterizedType, TypeVariable, GenericArrayType, and WildcardType, while Class implements Type for raw and primitive types.
ParameterizedType provides methods such as Type getRawType(), Type[] getActualTypeArguments(), and Type getOwnerType() to inspect generic type information, illustrated with Map<String, String> examples.
TypeVariable represents type parameters declared by generic declarations, offering Type[] getBounds(), D getGenericDeclaration(), and String getName(). It can only use extends for bounds, not super.
GenericArrayType models generic array types, exposing Type getGenericComponentType(). Examples show how arrays of List<String>[], T[], and primitive arrays behave when queried.
WildcardType represents wildcard generics like ? extends Number or ? super Integer, with methods Type[] getUpperBounds() and Type[] getLowerBounds(). Current implementations return single‑element arrays.
The article also explains why generic‑related types cannot be unified under Class, the role of type erasure, and how the Type hierarchy enables reflective operations on generic information.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ctrip Technology
Official Ctrip Technology account, sharing and discussing growth.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
