开发者

In Scala, what is the difference between Any and Object?

开发者 https://www.devze.com 2023-03-30 05:54 出处:网络
Suppose I have the following java method protected void onEvent(Object obj) { } The Scala compiler accepts

Suppose I have the following java method

protected void onEvent(Object obj) {

    }

The Scala compiler accepts

protected override def onEvent(event: Any)

and开发者_开发技巧

protected override def onEvent(event: Object)

Is there any difference between the two?


There is an article on scala-lang with great diagram (I even put it on the wall). And also need to be mentioned:

If Scala is used in the context of a Java runtime environment, then scala.AnyRef corresponds to java.lang.Object.


Any includes things that are not Objects in Java; it includes primitive types and also Nothing. Object is the same class as in Java, so it definitely excludes primitives.

0

精彩评论

暂无评论...
验证码 换一张
取 消