-
Notifications
You must be signed in to change notification settings - Fork 14
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
Replace static forwarders by a non-$ method to get the module #573
Comments
I don't recall this ever being proposed before. I'm rather hesitant about this change. (Maybe I need time to get used to the idea, since it's new to me.) If we want to make a change in this area, I would suggest not deprecating and not removing, but making them opt-in via a compiler flag. But even that, I'm hesitant about. I think we'd need to discuss it on https://contributors.scala-lang.org and see what the community thinks. I used static forwarders all the time when I worked on a large mixed Java/Scala codebase. It's one of the features that makes it not just possible, but convenient for Java users to start sneaking Scala code into mixed codebases, or to write Scala libraries that are usable from Java without annoying the Java clients with extra ceremony. Making the forwarders opt-in would reduce the harm in those scenarios, but it wouldn't remove it, because what if you don't control the Scala code in question, you have to ask the author to enable the forwarders, if it isn't the default. What about making the forwarders opt-out, so there's an escape hatch in cases where they're getting in the way? Thinking out loud. |
Also, I've never been personally been bitten by a static forwarder, I haven't personally experienced the downside. In order to justify the change to the community, I think you and/or Jason would need to be explicit about what the downsides of forwarders are. |
You might be on the right track here: these forwarders are a bit annoying from our perspective, selecting the right methods is a bit of a struggle. So maybe they look worse with the compiler writer's bias. |
one further thought: we might ask within Lightbend if the static forwarders are considered valuable by Akka, Play, Lagom, etc, they're the biggest users of Scala-for-Java-consumption |
Good idea. cc @patriknw, @marcospereira, @ignasi35. To summarize, currently
So Java clients can write |
You mean |
right, fixed! |
@lrytz We use |
It's common in Java to have a static method or field to access the instance of a singleton, like: Foo.INSTANCE.doThing(); (There are various implementations for singletons in Java, I think Effective Java explains them). In Akka there seems to be some precedence of defining For true static methods, for Java or other reasons, SIP-30 is relevant: |
Would this single-out |
@lrytz shall we close this? |
Yeah, seems like this isn't really feasible. |
While fixing the issues with static forwarders, @retronym suggested we should stop emitting those forwarders and instead emit a single static method to access the companion module.
Proposal:
object A
generatespublic static A$ module() { return A$.MODULE$ }
in classA
)Opinions? Did we discuss this before?
The text was updated successfully, but these errors were encountered: