Java reflection get parameter type

The getTypeParameters() is used to get the array of type variables if there are any type parameters associated with the class.

Example

ReflectionTest.java

package com.w3spoint;
 
import java.lang.reflect.TypeVariable;
 
public class ReflectionTest {
	public static void main(String args[]){
		try {
			TypeVariable<?>[] typeParameters = Class.forName("java.util.TreeMap").getTypeParameters();
			for(TypeVariable<?> t : typeParameters)
			System.out.println(t.getName());
		} catch (Exception e) {
			e.printStackTrace();
		}  
	}
}

Output

K
V
Content Protection by DMCA.com
Please Share