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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2871822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 02:09:31  来源:igfitidea点击:

How do I exclude/rename some classes from import in Scala?

scalascala-2.8

提问by Alexey Romanov

Language FAQsays

语言常见问题

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

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

应该从包导入所有类scala.collection.mutable,除了MapSet。但它给了我这个错误:

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

Is there still a way to do this?

还有办法做到这一点吗?

回答by Patrick

The _has to be put at the end - not at the beginning:

_端部有被投入-而不是开头:

Exclude Map and Set from the import

从导入中排除 Map 和 Set

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

Exclude Set and rename Map to ScalaMutableMap

排除 Set 并将 Map 重命名为 ScalaMutableMap

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

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

请参阅Scala Reference 中的详细信息,第 50 页,第 4.7 段