【发布时间】:2021-01-31 23:05:45
【问题描述】:
所以,这个大学练习要求编写一个方法,将Function<Short, Short> 作为参数,结果类型为Function<Short, Short>。它应该返回函数除以 9 的结果。
这是我编写的代码,虽然我非常有信心它应该可以工作,但 eclipse 在第 16 行显示了一个我根本无法理解的错误:
"Type mismatch: cannot convert from Function<Short,Object> to Function<Short,Short>.
如果我将Function<Integer, Integer> 放在两者中,或者如果我在返回类型中写入Function<Short, Object> 并将参数保留为 Function
public Function<Short, Short> ulmic(Function<Short, Short> period) {
return period.andThen(a -> a / 9);
}
【问题讨论】:
标签: java eclipse function java-8 short