更不用说为什么它是合法的,为什么这甚至会回归真实
scala> class Bla {
def hello(x: Any): Boolean = x.toString.length == 2
}
defined class Bla
scala> new Bla().hello()
res0: Boolean = true
Run Code Online (Sandbox Code Playgroud)
使用-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
Run Code Online (Sandbox Code Playgroud)
警告信息的含义是:
hello()被解释为hello(())
,因为().toString = "()"该方法返回true.
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |