package generic;public class GenericOne { public static void main(String[] args) { // TODO Auto-generated method stub GenericOne.getMiddle("a","b","c"); } /** * 泛型可以被不同类型的对象重用 * * 构造函数可以省略泛型类型 */ //定义简单泛型类 class Pair { private T first; private T second; public Pair(){} public Pair(T first, T second) { super(); this.first = first; this.second = second; } public T getFirst() { return first; } public void setFirst(T first) { this.first = first; } public T getSecond() { return second; } public void setSecond(T second) { this.second = second; }; } //泛型方法,可以定义在泛型或非泛型方法中 //在方法名的方扩号内定义具体的类 public static T getMiddle(T ... a){ return a[a.length/2]; }}