我有
Java 8方法引用与泛型类型相结合的问题.我已经简化了我的问题,明确问题所在.以下代码失败:
public static void main(String[] args) { new Mapper(TestEvent::setId); } private static class Mapper<T> { private BiConsumer<TestEvent,T> setter; private Mapper(BiConsumer<TestEvent,T> setter) { this.setter = setter; } } private static class TestEvent { public void setId(Long id) { } }
BiConsumer<TestEvent,Long> consumer = TestEvent::setId; new Mapper(consumer);
一切都奏效有人可以解释为什么吗