Java泛型问题总结

package com.liming.collection;

import java.util.Collection;

public class Test {
    public static void main(String[] args){
        System.out.println("TestCollection");

        MyCollection<String,Integer,Boolean,String,Integer,Double,Boolean> ms = new MyCollection<>();
     //   MyCollection<Integer,Boolean,Integer> mi = new MyCollection<>();
        ms.setStr("我爱祖国");

     //   mi.setStr(888);

        ms.setT1(123456);

     //   System.out.println(ms+" "+mi);
        System.out.println(ms.getT1());
    }
}

//ETV是代表类型字符,并没有明确具体类型 ,只有再声明变量的时候传递类型参数的时候确定具体的类型
class MyCollection<AA,BB,CC,DD,EE,FF,GG> {
    AA str;
    BB t1;

    public BB getT1() {
        return t1;
    }

    public void setT1(BB t1) {
        this.t1 = t1;
    }

    public void setStr(AA str) {
        this.str = str;
    }

    public AA getStr() {
        return str;
    }

    @Override
    public String toString() {
        return str.toString();
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_44702017/article/details/89073422