Why does Function.identity() break type reification but t -> t does not?

前端 未结 1 1753
悲&欢浪女
悲&欢浪女 2021-02-20 13:32

Answers found at Java 8 lambdas, Function.identity() or t->t seem to imply that Function.identity() is almost always equivalent to t -> t. Howeve

1条回答
  •  清歌不尽
    2021-02-20 14:15

    Ecj is able to infere the correct(?) type argument (Integer) to match the constraints. Javac for some reason comes to a different result.

    Thats not the first time javac/ecj behave differently in inference of type parameters.

    In that case you can give javac a hint with Function.identity() to make it compileable with javac.

    For the difference between Function.identity() and t->t:

    • Function.identity() is Function
    • t->t in that case is Function

    So t->t is more flexible in the methods it can match to.

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