开发者

Unimporting in Scala

开发者 https://www.devze.com 2022-12-10 15:13 出处:网络
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:

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.开发者_StackOverflow社区awt.List

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


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

精彩评论

暂无评论...
验证码 换一张
取 消