考虑下列课程:
class Foo<T> { void handle(T t) { System.out.println("handling " + t); } public static void main(String[] args) { List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); Foo<Integer> f = new Foo<>(); list.forEach(f::handle); // compiles fine //list.forEach(obj -> f.handle(obj));// compilation error f = new Foo<>(); // reassign f } }
为什么我得到obj的编译错误 – > f.handle(obj),但不适用于f :: handle?