Consider the following example
enum Foo:
case Bar1, Bar2, Bar3, Bar4
import Foo.*
val one = valueOf[1] //error: method valueOf in object Foo does not take type parameters
It’s very common to import an enumeration object namespace to get all its cases. However we also get the method like valueOf
imported to the scope. I wonder if there is a good language solution here.
Two solutions I can think of:
- Limited wildcard import/export like
import Foo.class, object, val
to be explicit about what identifiers should be implemented, but still as a wildcard. - Modifier to prevent import/export under wildcard imports like
explicit def valueOf ...
, soexplicit
identifiers can only be imported/exported when are explicitly referenced in the import/export statement.
Note:
Yes, I’m aware that in the example above it’s possible to exclude valueOf
via import Foo.{valueOf => _, *}
, but I wonder if this problem is more common and requires a better general solution.