---
title: "获取泛型转过来的类"
author: "java_script"
date: "2012-04-20T17:00:03Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-04-20T17:00:03Z"
id: 1491634
url: "https://java-script.iteye.com/blog/1491634"
---

public Class getGenericType(int index) {
		  Type genType = getClass().getGenericSuperclass();
		  if (!(genType instanceof ParameterizedType)) {
		   return Object.class;
		  }
		  Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
		  if (index >= params.length || index < 0) {
		   throw new RuntimeException("Index outof bounds");
		  }
		  if (!(params[index] instanceof Class)) {
		   return Object.class;
		  }
		  return (Class) params[index];
		 }

例如：Class<T,E>;T为0索引