Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    public static <T> Class<T> generateType(Class<?> klass) {
        Type type = klass.getGenericSuperclass();
        if (type instanceof ParameterizedType) {
            ParameterizedType paramType = (ParameterizedType) type;
            Type[] actualTypes = paramType.getActualTypeArguments();
            if (actualTypes != null && actualTypes.length > 0) {
                return (Class<T>) actualTypes[0];
            }
        }

        return null;
    }
}