为什么在没有任何参数的情况下调用一个接受Any的方法是合法的?

Jag*_*gat 6 scala

更不用说为什么它是合法的,为什么这甚至会回归真实

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)

Jag*_*gat 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
Run Code Online (Sandbox Code Playgroud)

警告信息的含义是:

hello()被解释为hello(()) ,因为().toString = "()"该方法返回true.