为什么返回类型是函数< t,r>在Groovy中忽略?
以下简单代码解释了我的困惑:
class Main {
static void f(Function<Float, Float> c) {
println(c.apply(0.0f))
}
static void main(String[] args) {
Closure<String> c = {"hi"}
f(c)
}
}
我不知道为什么编译器不抱怨cloture&lt; string&gt;
不适合function&lt; float,float&gt;
。似乎我可以将任何内容传递给f()
。
The following simple code explains my confusion:
class Main {
static void f(Function<Float, Float> c) {
println(c.apply(0.0f))
}
static void main(String[] args) {
Closure<String> c = {"hi"}
f(c)
}
}
I have no idea why the compiler does not complain that Closure<String>
is not appropriate for Function<Float, Float>
. Seems that I can pass anything to f()
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下代码
打印
the following code
prints