使用通配符导入符号,但重命名或忽略其中一些符号 [英] Import symbols with wildcard, but rename or ignore some of them

查看:171
本文介绍了使用通配符导入符号,但重命名或忽略其中一些符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想导入大多数Scala Swing符号,但有一些例外。例外是我提供了我自己的实现的类,比如 ToggleButton ,它在 scala.swing中只有一个基本的实现(没有构造函数 Action )。

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).

我可以为我的类使用不同的名称(如 ToggleButtonEx ),但这使得使用它们不那么自然。

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?

推荐答案

你可以使用排除某些名称的下划线。

You can use an underscore to exclude certain names.

import scala.swing.{ToggleButton => _, _}
import mydomain.swing._

另一种解决方案是导入<单独code> ToggleButton 。由于个别导入优先于通配符导入,因此对 ToggleButton 的引用将不再含糊不清。

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, _}

这篇关于使用通配符导入符号,但重命名或忽略其中一些符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆