Import symbols with wildcard, but rename or ignore some of them

孤人 提交于 2019-12-11 11:43:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!