Close

Java Reflection - Class.getTypeParameters() Examples

Code Snippets Java Reflection Java 


Class:

java.lang.Class

java.lang.Objectjava.lang.Objectjava.lang.Classjava.lang.Classjava.io.SerializableSerializablejava.lang.reflect.GenericDeclarationGenericDeclarationjava.lang.reflect.TypeTypejava.lang.reflect.AnnotatedElementAnnotatedElementLogicBig

Method:

public TypeVariable<Class<T>>[] getTypeParameters()
Returns:
an array of TypeVariable objects that represent the type variables declared by this generic declaration.


Examples


package com.logicbig.example.clazz;

import java.lang.reflect.TypeVariable;

public class GetTypeParametersExample {

public static void main(String... args) {
Class<MyClass> c = MyClass.class;
TypeVariable<Class<MyClass>>[] typeParameters = c.getTypeParameters();
for (TypeVariable<Class<MyClass>> typeParameter : typeParameters) {
System.out.println(typeParameter);
}
}

private static class MyClass<T, S> {}
}

Output

T
S




See Also