在Scala中不重要 [英] Unimporting in Scala

查看:86
本文介绍了在Scala中不重要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近听到一些建议unmport from Predef的隐式转换 - 我认为这意味着可以 unimport 不需要的类也是:

I heard recently some advice to "unimport an implicit conversion from Predef" - I presume that this means it is possible to unimport unwanted classes too:

import java.awt._
unimport java.awt.List

但这不是unmport的语法(即没有这样的 unimport 关键字)。什么是正确的语法?

But this is not the syntax of an "unimport" (i.e. there is no such unimport keyword). What is the correct syntax?

推荐答案

使用导入别名功能,但将不需要的类重命名为_。由于无法在Scala代码中将_作为类名访问,因此它会将重命名的类隐藏为非限定访问。

Use the import alias feature but rename the "unwanted class" to "_". Since "_" can not be accessed in Scala code as a classname, it hides the renamed class from unqualified access.

import java.awt.{List => _, _}

这篇关于在Scala中不重要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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