链接功能接口 - IntUnaryOperator 与 UnaryOperator

alw*_*ous 5 java lambda unary-operator

我还在学习函数式接口。我想知道为什么我可以将 a 链接UnaryOperator到a的末尾Function,但不能将 an 链接IntUnaryOperator到同一个 Function 的末尾。

UnaryOperator <String> twoOfMe = s -> s + s;
Function <String, Integer> convertMe = s -> Integer.parseInt (s);

UnaryOperator <Integer> twiceMe = n -> 2*n;

IntUnaryOperator doubleMe = n -> 2*n;

int a = twoOfMe.andThen(convertMe).andThen(twiceMe).apply ("2");

int b = twoOfMe.andThen(convertMe).andThen(doubleMe).apply ("2");
Run Code Online (Sandbox Code Playgroud)

int a使用twiceMeint b不适用于doubleMe.

谢谢

编辑:它说不兼容的类型。必需的整数。找到 java.lang.Object

Era*_*ran 5

andThen(Function<? super R, ? extends V> after)期待Function争论。UnaryOperator<Integer>是 的子接口Function<Integer,Integer>,匹配。IntUnaryOperatorFunction接口无关,因此doubleMe不能传递给andThen.