Skip to content

Resolve inherited Java static method #7386

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
scabug opened this issue Apr 18, 2013 · 8 comments · Fixed by scala/scala#8432
Closed

Resolve inherited Java static method #7386

scabug opened this issue Apr 18, 2013 · 8 comments · Fixed by scala/scala#8432
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Apr 18, 2013

Inherit static method from Java class is not recognized by Scala class
Here there is an small and simple example:

MyClass.java
public class MyClass extends MyClassBase {}

abstract class MyClassBase {
  public static void myStaticBaseMethod() {}
}

MyScalaClass.scala
class MyScalaClass {
  MyClassBase.myStaticBaseMethod() //compiles
  MyClass.myStaticBaseMethod() //no compiles. Wrong!!!
}
@scabug
Copy link
Author

scabug commented Apr 18, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7386?orig=1
Reporter: Gaston Lodieu (glodieu)
Affected Versions: 2.9.2, 2.10.1

@scabug
Copy link
Author

scabug commented Apr 22, 2013

@adriaanm said:
stumbled into another problem while exploring this in the repl

scala> MyClassBase.myStaticBaseMethod()
java.lang.IllegalAccessError: tried to access class MyClassBase from class 
	at .<init>(<console>:8)

@scabug
Copy link
Author

scabug commented Nov 29, 2016

@SethTisue said:
in both 2.11.8 and 2.12.0, the IllegalAccessError mentioned by Adriaan no longer occurs. (You correctly get a "object MyClassBase cannot be accessed in package " compile-time error, because MyClassBase isn't declared public.)

As for the original issue, I suggest we simply close it as "Not a Bug". Scala simply doesn't have the Java concept of statics. We have companion objects instead, but no inheritance relationship exists between the companion objects of a subclass and a superclass. Following Java here and allowing MyClass.myStaticBaseMethod wouldn't be consistent with that.

You can call the method through the superclass, so I don't see that any actual interop problem arises here.

@scabug
Copy link
Author

scabug commented Dec 20, 2016

Stefano Baghino (stefanobaghino) said:
I see why supporting the same concept wouldn't make sense in Scala (and would probably introduce unnecessary complexity).
Do you think it would be feasible just to introduce an error message that can be a little bit friendlier towards those coming from Java, perhaps suggesting what the user can do?
I've just stumbled on this error trying to use static methods defined on an InputFormat implementation to run a job on Spark (Hadoop ecosystem, in particular I'm using an AccumuloInputFormat).

@scabug
Copy link
Author

scabug commented Dec 20, 2016

@lrytz said:
test case in scala/scala#5606

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@SethTisue
Copy link
Member

@lrytz do you agree this should be closed as "not a bug"? scala/scala#5606 doesn't aim to "fix" this ticket, right?

@lrytz
Copy link
Member

lrytz commented Jul 17, 2017

Yes, I agree

@lrytz lrytz closed this as completed Jul 17, 2017
@SethTisue
Copy link
Member

Do you think it would be feasible just to introduce an error message that can be a little bit friendlier towards those coming from Java, perhaps suggesting what the user can do

a pull request with that would be welcome, as far as I can see. (I don't think it merits an additional ticket — there are too many improvable error messages to have individual tickets for them all)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants