Skip to content

Java objects inherit methods from Any #5313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
allanrenucci opened this issue Oct 23, 2018 · 2 comments
Closed

Java objects inherit methods from Any #5313

allanrenucci opened this issue Oct 23, 2018 · 2 comments

Comments

@allanrenucci
Copy link
Contributor

With Dotty:

scala> System.getClass                                                                                                                                                                                          
java.lang.NoClassDefFoundError: java/lang/System$
	at rs$line$1$.<init>(rs$line$1:1)
	...

with Scala 2:

scala> System.getClass
<console>:12: error: value getClass is not a member of object System
Note that System extends Any, not AnyRef.
Such types can participate in value classes, but instances
cannot appear in singleton types or in reference comparisons.
       System.getClass
@smarter
Copy link
Member

smarter commented Oct 23, 2018

Note that getClass (and other methods such as hashCode) are defined on Any, so just extending Any instead of AnyRef won't prevent this.

@allanrenucci allanrenucci changed the title Java objects extend AnyRef instead of Any Java objects inherit methods from Any Oct 23, 2018
@Jasper-M
Copy link
Contributor

Jasper-M commented Nov 5, 2018

The Scala 2 error doesn't make a lot of sense either.
Scala doesn't treat System as an object. It just has some kind of magical treatment of Java defined classes with static methods.

odersky added a commit to dotty-staging/dotty that referenced this issue Mar 6, 2020
@smarter smarter closed this as completed in a830df2 Mar 6, 2020
smarter added a commit that referenced this issue Mar 6, 2020
Fix #5313: Don't allow selecting AnyRef methods on Java static compan…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants