How to just import an object called "*" from a package?

In Scala 2, we just use an underscore to denote importing all from a package. And tutorials applaud the decision because it avoids confusion with an object named as a star. However, in Scala 3 we use a star to do the same thing. I am just curious about the syntax to import an object named β€œ*”.
Also I have a suggestion. How about denoting importing all with a pair of empty braces?

Here is a simple example that import β€œ*” from package use back quote β€œ`”

object Test extends App {
  object SomePackage {
    def *(that: Any) = println(that)
    def fun1(a: Int) = println(2 * a)
  }

  import SomePackage.`*`

  // fun1(222) it compiles failed
  *(22)
}
1 Like

Which tutorials applaud it?

As a footnote, underscore previously had the same problem.

Thanks for pointint out. I should think of this solution.

Well, even a book by Martin Odersky et al. says something like β€œat least the star is a legal identifier”. I read the Chinese version and cannot find the original English words. Actually I still agree with the authors. Underscore has many dedicated usages, and is usually not (possibly illegal?) for naming a customized object.

Also, that is an interesting idea to use empty braces. Scala 3 still needs given, so it still needs wildcard for import x.{given, *}.

* is also used for other syntax, so it used to error when used as a name in some cases.

1 Like