Scala导入多个包 [英] Scala import multiple packages
问题描述
我在自己的程序包中有一些Scala类和对象.每个包都有一个定义一些隐式的包对象,例如,import com.foo.bar._
从bar
包中导入所有隐式和类
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
我想知道的是,有没有一种方法可以定义伞"导入,例如com.foo.all
,这样
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._
等同于
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 shortest form I can come up is:
import com.foo._, bar._, baz._, qux._
例如:
import scala.collection.mutable._, PriorityQueue._, ArrayBuffer._
编辑
也许您只想使用某些特殊的东西,如@ alex23指出的那样 ,所以您可以这样写:
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._
这篇关于Scala导入多个包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!