public class Bag<T>{
    private T content;
    
    public Bag(T content) {
        this.content = content;
    }

    public T get() {
        return this.content;
    }

    public void set(T content) {
        this.content = content;
    }

    public static void main(String[] args){
      Bag<String> bag=new Bag<String>("mybook");
      //Integer content1=bag.get(); //编译出错
      String content2=bag.get(); //无需进行强制类型转换
    }
}


/****************************************************
 * 作者：孙卫琴                                     *
 * 来源：<<Java面向对象编程>>                       *
 * 技术支持网址：www.javathinker.net                *
 ***************************************************/
