如何从Scala的导入中排除/重命名某些类?

时间:2021-09-28 16:52:40

Language FAQ says

语言FAQ说

import scala.collection.mutable.{_, Map => _, Set => _}

should import all classes from package scala.collection.mutable, except Map and Set. But it gives me this error:

应该从包scala.collection导入所有类。可变的,除了映射和集合。

error: '}' expected but ',' found.
       import scala.collection.mutable.{_, Map => _, Set => _}

Is there still a way to do this?

还有办法做到这一点吗?

1 个解决方案

#1


77  

The _ has to be put at the end - not at the beginning:

_必须放在末尾——而不是在开头:

Exclude Map and Set from the import

从导入中排除映射和设置

import scala.collection.mutable.{Map => _, Set => _, _}

Exclude Set and rename Map to ScalaMutableMap

排除Set和重命名映射到ScalaMutableMap

import scala.collection.mutable.{Map=>ScalaMutableMap, Set => _, _}

See the detailed info in Scala Refererence, page 50, paragraph 4.7

参见Scala Refererence的详细信息,第50页,第4.7段。

#1


77  

The _ has to be put at the end - not at the beginning:

_必须放在末尾——而不是在开头:

Exclude Map and Set from the import

从导入中排除映射和设置

import scala.collection.mutable.{Map => _, Set => _, _}

Exclude Set and rename Map to ScalaMutableMap

排除Set和重命名映射到ScalaMutableMap

import scala.collection.mutable.{Map=>ScalaMutableMap, Set => _, _}

See the detailed info in Scala Refererence, page 50, paragraph 4.7

参见Scala Refererence的详细信息,第50页,第4.7段。