deltanovember
deltanovember

Reputation: 44051

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

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?

Upvotes: 38

Views: 13300

Answers (2)

4e6
4e6

Reputation: 10776

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.

Upvotes: 26

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

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.

Upvotes: 26

Related Questions