Skip to content

52 函数值 ​

具名函数可以存入 Function<Integer(Integer)> 类型变量后再调用;apply 也能把同样的函数值作为参数接收。

norm
Integer double(Integer number) {
  return number * 2
}

Integer apply(Function<Integer(Integer)> action, Integer input) {
  return action(input)
}

main() {
  Function<Integer(Integer)> saved = double
  printLine(saved(4))
  printLine(apply(action: saved, input: 7))
}

预期输出:

text
8
14

动手试试:不用 saved 变量,直接把 double 传给 apply。

精确规则:语言参考。

Norm 0.25