泛型类定义:

 

 

 

public class BoxGeneri<E> {

    private E name;

    public BoxGeneri() {
    }

    public BoxGeneri(E name) {
        this.name = name;
    }

    public E getName() {
        return name;
    }

    public void setName(E name) {
        this.name = name;
    }

}

public class GeneriTest {

    public static void main(String[] args) {
        BoxGeneri<String> b = new BoxGeneri<>();
        b.setName("box");
        System.out.println(b.getName());
    }

}