/** * 功能:泛型的简单说明 */ package com.zjr; import java.lang.reflect.Method; public class Text1 { public static void main(String args[]){ Gen gen=new Gen(new Bird()); gen.showTypeName(); } } //定义一个鸟类 class Bird{ public void text(){ System.out.println("Hello!"); } public void sum(int a,int b){ System.out.println(a+b); } } //定义一个类 class Gen{ private T o; //构造函数 public Gen(T a){ o=a; } //得到T的类型名称 public void showTypeName(){ System.out.println("类型:"+o.getClass().getName()); //通过反射机制,可以得到T类的许多信息,如函数的名称,返回类型等等 Method[] m=o.getClass().getDeclaredMethods(); //打印 for (int i=0;i