【泛型 泛型 泛型】

TestGeneric

public class TestGeneric {
    
    

    public static void main(String[] args) {
    
    

        MyCollection<String> mc=new MyCollection<>();

        mc.set("若颂",0);

        String b=mc.get(0);
    }
}

MyCollection

class MyCollection<E>{
    
    

    Object[] objs=new Object[5];

    public void set(E e,int index){
    
    
        objs[index]=e;
    }

    public E get(int index)
    {
    
    
        return (E)objs[index];
    }
}

猜你喜欢

转载自blog.csdn.net/RSssr/article/details/109434094