相关疑难解决方法(0)

Java 8函数总是返回相同的值而不考虑参数

Java 8中是否有预定义函数可以执行以下操作:

static <T, R> Function<T, R> constant(R val) {
    return (T t) -> {
        return val;
   };
}
Run Code Online (Sandbox Code Playgroud)

在我尝试将整数解析为罗马数字时,回答人们对我为什么需要此函数的查询是真正的用法:

// returns the stream of roman numeral symbol based
// on the digit (n) and the exponent (of 10)
private static Stream<Symbol> parseDigit(int n, int exp) {
    if (n < 1) return Stream.empty();
    Symbol base = Symbol.base(exp);
    if (n < 4) {
        return IntStream.range(0, n).mapToObj(i -> base);
    } else if (n == 4) {
        return Stream.of(base, Symbol.fifth(exp));
    } else if …
Run Code Online (Sandbox Code Playgroud)

java functional-programming java-8

8
推荐指数
1
解决办法
2781
查看次数

标签 统计

functional-programming ×1

java ×1

java-8 ×1