I've got some Scala classes and objects, in their own packages. Each package has a package object defining some implicits, so for example import com.foo.bar._
imports all implicits and classes from the bar
package
What I'd like to know is, is there a way to define an "umbrella" import, say com.foo.all
, such that
import com.foo.all._
is equivalent to
import com.foo.bar._
import com.foo.baz._
import com.foo.qux._
...
I can understand that this might be a little unclear, but if I we consider the case where I have a large number of my own packages, this would clearly be more concise.
The Scala way to import multiple classes/objects from the same package is:
import scala.collection.immutable.{Map, HashMap, etc}
Cool Scala only trick: aliasing/renaming
import java.util.{Collection => JavaCollection}
The shortest form I can come up is:
import com.foo._, bar._, baz._, qux._
For example:
import scala.collection.mutable._, PriorityQueue._, ArrayBuffer._
EDIT
Perhaps, you want to use only some particular things, as @alex23 pointed out, so you may write:
import com.foo.{foo, bar, baz}, bar._, baz._, qux._
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With