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
Java wrappers need not be case classes #10104
Conversation
Only 186 issues. That includes all the junk case class synthetic methods. Maybe it's possible to quarantine the internal package. |
685fe35
to
976bd56
Compare
976bd56
to
59dd3bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 (for the record, the changed classes are private[collection]
)
This change causes lots of problems in a large code base that I am working on. When scala> import scala.jdk.CollectionConverters.IterableHasAsJava
import scala.jdk.CollectionConverters.IterableHasAsJava
scala> Nil.asJavaCollection == Nil.asJavaCollection
val res0: Boolean = false
scala> Set("foo").asJavaCollection == Set("foo").asJavaCollection
val res1: Boolean = false |
@scala/collections wdyt? is this something we should consider reverting? on the one hand, as a behavior change it seems like fair game for a minor version. (recall that Scala 2 versions are epoch.major.minor, not major.minor.patch on the other hand, if the change isn't that high-value, then maybe the disruption isn't worth it on the other other hand, it seems unlikely we'll be doing 2.13.11 in less than 3-4 months, at which point I'm not sure the possible disruption of changing it back is worth it — we might have felt differently if the report had come in during the brief 2.13.10 window would anyone like to make a specific, evidence-supported argument that this wasn't a fair-game change...? |
note that https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html#equals-java.lang.Object- says:
|
@kasparito Sorry for the trouble. Universal methods FTW. "Nothing is internal API." The motivation was unexpected member overrides in the internal classes; case classiness was taken as a convenience for construction. Reliance on equals and hashCode didn't come up. Maybe hashCode not so much because of mutability. I think the expectation that it just works is Also compare scala/bug#10663 where the asJava side has a contract that is not lax. |
I took a look, and it mostly just works. However,
The other adapters extend the specific base classes which do implement the expected equals. Probably it's harmless to remain compatible with the previous behavior for I'll open a ticket to track the change. |
resolved by #10205 |
Inspired by scala/scala3#15764 (comment) to consider whether the wrapper classes ought to be case classes, as they have been since early days.
The hierarchy is complex (because collections).
ConcurrentMapWrapper
overrode theunderlying
case class field inMutableMapWrapper
, to narrow the result type. Now it providesunderlyingConcurrentMap
as a convenience.Arguably, the pattern matches are easier to read.
It would be nice to backport universal apply and compile library with
-Xsource:3
.Mima may disagree and require persuading.