interface Collection<E> { public <T> boolean containsAll(Collection<T> c); public <T extends E> boolean addAll(Collection<T> c); // hey, type variables can have bounds too! }
刚开始看到这样的方法定义时不知道方法返回类型前面的<T>有什么用,其实这就是泛型方法的定义方式。
以前总是通过在类的定义中加参数化类型,如果只需对某个方法做泛型处理,可以通过这种方式将方法的参数和返回值类型泛型化。