Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何在ttl里面使用BinaryOperator #534

Closed
Bughue opened this issue Aug 10, 2023 · 1 comment
Closed

如何在ttl里面使用BinaryOperator #534

Bughue opened this issue Aug 10, 2023 · 1 comment
Assignees
Labels
❓question Further information is requested

Comments

@Bughue
Copy link

Bughue commented Aug 10, 2023

BinaryOperator继承自BiFunction,但是按ttl现在提供的wrappers,貌似怎么写都不对,请教一下这个要怎么写

@oldratlee
Copy link
Member

oldratlee commented Aug 10, 2023

@Bughue

  • 注意,使用wrapBiFunction()方法,而不是废弃的wrap方法
  • TtlWrappers没有直接提供 BinaryOperatorwrap方法;
    如果你有需要,可以自己照着wrapBiFunction实现一个wrapBinaryOperator方法

下面是一些写法示例:

// 显式写上参数类型
TtlWrappers.wrapBiFunction((Integer x1, Integer x2) -> x1 + x2);
TtlWrappers.wrapBiFunction((Integer x1, Integer x2) -> {
    int sum = x1 + x2;
    return sum * 42;
});

BinaryOperator<Integer> f0 = (x1, x2) -> x1 + x2;
BiFunction<Integer, Integer, Integer> w0 = TtlWrappers.wrapBiFunction(f0);

BiFunction<Integer, Integer, Integer> w1 = TtlWrappers.wrapBiFunction((x1, x2) -> x1 + x2);
BiFunction<Integer, Integer, Integer> w2 = TtlWrappers.wrapBiFunction(Integer::sum);

BiFunction<Integer, Integer, Integer> f3 = (x1, x2) -> x1 + x2;
BiFunction<Integer, Integer, Integer> w3 = TtlWrappers.wrapBiFunction(f3);

PS: 上面这些是Java写法(Lambda语法)的区别。

@oldratlee oldratlee added the ❓question Further information is requested label Aug 10, 2023
@oldratlee oldratlee self-assigned this Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants