public static void main(String[] args) throws Exception { String str = "1,2,3,4,5,6"; Function
要匹配您问题中的代码,您可以将其包装到这样的类中:
public class Combiner { private Object input; public Combiner(Object input) { this.input = input; } @SuppressWarnings("unchecked") @SafeVarargs public final R combineFunctions(Function... functions) { return (R) Arrays.stream(functions) .reduce(Function::andThen) .orElseThrow(() -> new IllegalArgumentException("No functions to combine")) .apply(input); } }