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

1

52

Language FAQ says

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:

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

Is there still a way to do this?

Adler answered 20/5, 2010 at 7:41 Comment(2)
Actually, it says this: import scala.collection.mutable.{Map => _, Set => _, _}Cambria
Yes, now it does: scala.sygneca.com/faqs/language?rev=1273682255&do=diffAdler
B
98

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

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

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

Bootlace answered 20/5, 2010 at 7:57 Comment(1)
"This is useful if there is a final wildcard in the same import selector list, which imports all members not mentioned in previous import selectors."Honey

© 2022 - 2024 — McMap. All rights reserved.