Home > Mobile >  Using '*' instead of '_' in imports
Using '*' instead of '_' in imports

Time:11-08

I have a project which is the code of an API. In build.sbt the version of Scala is:

scalaVersion := "2.13.8"

In several Scala files I see imports using * instead of _ like this:

...
import sttp.tapir.*
...

How is that? It is my understanding that * can be used in Scala 3, but not in 2.1x ... I can't see any library (it's a big codebase) or something related to this ... Why does it works instead of showing compiling errors?

CodePudding user response:

To ease migration to Scala 3, some syntax of Scala 3 can be used in Scala 2.

See for instance the release note of Scala 2.13.7:

Align with Scala 3

...

Allow import x.{*, given} under -Xsource:3 (#9724 by @smarter)

...

(https://github.com/scala/scala/releases/tag/v2.13.7)

Though I'm not sure since when it is possible to use import X.* (in my understanding, this existed before 2.13.7).

  • Related