CodesJava

Easy learning with example program codes

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.codesjava;
 
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
Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki