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 {
    @SuppressWarnings("unchecked")
    public static Class findToken(Class<?> clazz, int tokenIndex) {
        Type superclass = clazz.getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new RuntimeException("Missing type parameter.");
        }
        Type entityType = ((ParameterizedType) superclass).getActualTypeArguments()[tokenIndex];
        if (!(entityType instanceof Class)) {
            throw new RuntimeException("Entity type not a class.");
        }
        return (Class) entityType;
    }
}