dig From Generic Type - Java Reflection

Java examples for Reflection:Generic

Description

dig From Generic Type

Demo Code


//package com.java2s;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class Main {
    static Class<?> digFromGenericType(Type genericType) {
        Type[] typeArguments = ((ParameterizedType) genericType)
                .getActualTypeArguments();
        Type type = typeArguments[0];
        if (type instanceof ParameterizedType) {
            return digFromGenericType(type);
        } else {//from   ww w. j a v  a 2  s.  c o m
            return (Class<?>) type;
        }

    }
}

Related Tutorials