//JDk1.5后,使用泛型来接收类中要操作的引用数据类型
//泛型类,什么时候用?当类中操作的引用数据类型不确定的时候,就使用泛型类。
class Tool<Q>
{
    private Q q;

    public Tool(Q q) {
        this.q = q;
    }

    public Q getQ() {
        return q;
    }

    public void setQ(Q q) {
        this.q = q;
    }
    
}

public class Person {

    public static void main(String[] args) {
 
        ArrayList<Tool<Car>>  list = new ArrayList<Tool<Car>>();
        list.add(new Tool(new Car("1234", 234)));
        
        Tool<Car> t = new Tool<Car>(new Car("a", 31));

    }
}

 

相关文章:

  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-07-04
  • 2022-12-23
  • 2021-08-24
猜你喜欢
  • 2022-12-23
  • 2021-07-29
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案