Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

lang.reflect.ParameterizedType: practical reference

lang.reflect.ParameterizedType: practical reference: ParameterizedType models a parameterized type such as List<String>, separating raw type from actual type arguments.

Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime

Syntax

java.lang.reflect.ParameterizedType

ParameterizedType models a parameterized type such as List, separating raw type from actual type arguments.

Use ParameterizedType to inspect a run-time generic signature such as Map<String, Integer>, including its raw type, owner, and actual type arguments.

It represents signature metadata, not reified element types: an object cannot be tested with instanceof List. Type arguments may themselves be WildcardType, TypeVariable, GenericArrayType, or another ParameterizedType.

A nested type can have a non-null owner type. Equality is structural across owner, raw type, and arguments, while missing or malformed signature types can fail during reflective resolution.

The example exercises the documented element in a small deterministic program and compares exact standard output.

Examples

public class Main {
    public static void main(String[] args) throws Exception {
        java.lang.reflect.Type type = new java.util.ArrayList<String>() {}.getClass().getGenericSuperclass();
        var parameterized = (java.lang.reflect.ParameterizedType) type;
        System.out.println(parameterized.getActualTypeArguments()[0]);
    }
}

Result

class java.lang.String

The example exercises the documented element in a small deterministic program and compares exact standard output.

Sources