【发布时间】:2020-03-29 12:59:15
【问题描述】:
我正在尝试使用 Java 8 实现管道设计模式,下面的文章供我参考:
https://stackoverflow.com/a/58713936/4770397
代码:
public abstract class Pipeline{
Function<Integer, Integer> addOne = it -> {
System.out.println(it + 1);
return it + 1;
};
Function<Integer, Integer> addTwo = it -> {
System.out.println(it + 2);
return it + 2;
};
Function<Integer, Integer> timesTwo = input -> {
System.out.println(input * 2);
return input * 2;
};
final Function<Integer, Integer> pipe = sourceInt
.andThen(timesTwo)
.andThen(addOne)
.andThen(addTwo);
}
我正在尝试添加一种抽象方法并想要覆盖它。
我正在尝试做类似的事情:
abstract BiFunction<Integer, Integer,Integer> overriden;
并将管道更改为:
final Function<Integer, Integer> pipe = sourceInt
.andThen(timesTwo)
.andThen(overriden)
.andThen(addOne)
.andThen(addTwo);
}
但问题是,我不知道将Function<Integer, Integer> 声明为抽象方法。
【问题讨论】:
标签: java java-8 functional-interface