问题
I want to import most Scala Swing symbols with a few exceptions. The exceptions are classes for which I have provided my own implementation, like ToggleButton
, which has only a rudimentary implementation in the scala.swing
(no constructor taking Action
).
I can use different names for my classes (like ToggleButtonEx
), but this makes using them less natural.
I am looking for something like:
import scala.swing.{ToggleButton => SToggleButton, _} // import all but ToggleButton
import mydomain.swing._ // contains ToggleButton as well
Is there some pattern matching syntax for import, or some other way to achieve this?
回答1:
You can use an underscore to exclude certain names.
import scala.swing.{ToggleButton => _, _}
import mydomain.swing._
An alternative solution is to import ToggleButton
individually. Since individual imports take precedence over wildcard ones, the reference to ToggleButton
will no longer be ambiguous.
import scala.swing._
import mydomain.swing.{ToggleButton, _}
来源:https://stackoverflow.com/questions/27945005/import-symbols-with-wildcard-but-rename-or-ignore-some-of-them