如何在 Scala 中从导入中排除/重命名某些类?
问题描述:
import scala.collection.mutable.{_, Map => _, Set => _}
应该从包scala.collection.mutable
中导入所有类,除了Map
和Set
.但它给了我这个错误:
should import all classes from package scala.collection.mutable
, except Map
and Set
. But it gives me this error:
error: '}' expected but ',' found.
import scala.collection.mutable.{_, Map => _, Set => _}
还有办法做到这一点吗?
Is there still a way to do this?
答
_
必须放在结尾 - 而不是开头:
The _
has to be put at the end - not at the beginning:
从导入中排除 Map 和 Set
import scala.collection.mutable.{Map => _, Set => _, _}
排除 Set 并将 Map 重命名为 ScalaMutableMap
import scala.collection.mutable.{Map=>ScalaMutableMap, Set => _, _}
在Scala参考中查看详细信息,第 50 页,第 4.7 段
See the detailed info in Scala Refererence, page 50, paragraph 4.7