更别说为什么它是合法的,为什么这甚至会回归
scala> class Bla {
def hello(x: Any): Boolean = x.toString.length == 2
}
defined class Bla
scala> new Bla().hello()
res0: Boolean = true
答案 0 :(得分:6)
使用-deprecation运行提供此
scala> scala> class Bla {
def hello(x: Any): Boolean = x.toString.length == 2
}
defined class Bla
scala> new Bla().hello()
<console>:13: warning: Adaptation of argument list by inserting () has been deprecated: leaky (Object-receiving) target makes this especially dangerous.
signature: Bla.hello(x: Any): Boolean
given arguments: <none>
after adaptation: Bla.hello((): Unit)
new Bla().hello()
^
res0: Boolean = true
警告信息的含义是:
hello()
被解释为hello(())
从().toString = "()"
开始,该方法返回true
。