Java 8 Method reference with generic types

后端 未结 1 1150
天涯浪人
天涯浪人 2021-01-17 16:39

I am having issues with Java 8 method reference combined with generic types. I have simplified my problem to make it clear where the problem lies. The following code fails:<

相关标签:
1条回答
  • 2021-01-17 17:06

    Currently you're trying to use the raw mapper type, which erases all kinds of things.

    As soon as you start using the generic type, all is fine - and type inference can help you:

    new Mapper<>(TestEvent::setId);
    

    Adding <> is all that's required to make your code compile.

    0 讨论(0)
提交回复
热议问题