码迷,mamicode.com
首页 > 其他好文 > 详细

What does “=>” mean in import in scala?(转自StackOverflow问答)

时间:2017-07-24 13:04:14      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:code   when   tar   package   ase   imp   ret   simple   http   



 

As others have mentioned, it‘s an import rename. There is however one further feature that proves astoundingly-useful on occasion that I would like to highlight: If you "rename" to _, the symbol is no longer imported.

This is useful in a few cases. The simplest is that you‘d like to do a wildcard import from two packages, but there‘s a name that‘s defined in both and you‘re only interested in one of them:

import java.io.{ File=>_, _ }
import somelibrary._

Now when you reference File, it will unambiguously use the somelibrary.File without having to fully-qualify it.

In that case, you could have also renamed java.io.File to another name to get it out of the way, but sometimes you really do not want a name visible at all. This is the case for packages that contain implicits. If you do not want a particular implicit conversion (e.g. if you‘d rather have a compile error) then you have to delete its name completely:

import somelibrary.{RichFile => _, _}
// Files now won‘t become surprise RichFiles

参考链接:

https://stackoverflow.com/questions/31652959/what-does-mean-in-import-in-scala

What does “=>” mean in import in scala?(转自StackOverflow问答)

标签:code   when   tar   package   ase   imp   ret   simple   http   

原文地址:http://www.cnblogs.com/hubavyn/p/7228123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!