-
Notifications
You must be signed in to change notification settings - Fork 87
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
CollectionConverters API for Scala 2.11/2.12 #208
Comments
Discussed on Monday next steps are:
|
The following change scala/scala@05f8f18#diff-2efa831ba3194fedd2a132bb246f2e22 "Add jdk.CollectionConverters, deprecate collection.JavaConverters" is a challenge for cross-compiled projects. Adding "jdk.CollectionConverters" to scala-collection-compat would give cross-compiled projects the opportunity to avoid deprecation warnings, by switching to "jdk.CollectionConverters". |
Another option I've see taken is disabling deprecation warnings when building with Scala 2.13. Or leaving them on but disabling fatal warnings when on 2.13. |
@DaniRey You can cross-compile warning-free with this helper beast: /** Magic to get cross-compiling access to `scala.jdk.CollectionConverters`
* with a fallback on `scala.collection.JavaConverters`, without deprecation
* warning in any Scala version.
*/
object JDKCollectionConvertersCompat {
object Scope1 {
object jdk {
type CollectionConverters = Int
}
}
import Scope1._
object Scope2 {
import scala.collection.{JavaConverters => CollectionConverters}
object Inner {
import scala._
import jdk.CollectionConverters
val Converters = CollectionConverters
}
}
val Converters = Scope2.Inner.Converters
} which you can then use as import JDKCollectionConvertersCompat.Converters._
val list = List(1, 2, 3)
val jList = list.asJava
println(jList) |
:mind_blown: I actually would need you to explain to me how that works... |
It works as follows. When compiling on 2.13The Then of course That means that the The contents of When compiling on 2.12 or earlierThe You'd then expect that The contents |
I follow!! Thanks for that. <3 |
I wanted to find a solution that exploited the fix that a local import now has binding precedence over a definition in another file, such as the package object. Given a package object, which could be separately compiled or only for 2.12:
then this works in the obvious way:
where obvious means that |
Initial support for Scala 2.13 scala/scala-collection-compat#217 scala/scala-parallel-collections#22 scala/scala-collection-compat#208 Signed-off-by: 35V LG84 <[email protected]>
To migrate the code and avoid the depreciation messages in 2.13.
The text was updated successfully, but these errors were encountered: