当定义的类的对象的类型不确定的时候,可以采用泛型类:
class Util<q> {//泛型类中的参数可以任意定义
private q obj;
public q getObj() {
return obj;
}
public void setObj(q obj) {
this.obj = obj;
}
}
public class GenericTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Util<Student> util = new Util<Student>();
util.setObj(new Student());
Student stu = util.getObj();
System.out.println(stu);
}
}