首页 > 其他 > 详细

Scala - 隐士转换和隐式参数

时间:2016-08-10 13:59:42      阅读:266      评论:0      收藏:0      [点我收藏+]

隐士转换是Scala提供的一种语法糖

Implicit definitions are those that the compiler is allowed to insert into a program in order to fix any of its type errors.

Sacla隐士转换的规则

Marking rule: Only definitions marked implicit are available

Scope rule: An inserted implicit conversion must be in scope as a single identifier, or be associated with the source or target type of the conversion

One-at-a-time rule: Only one implicit is inserted

Explicits-first rule: Whenever code type checks as it is written, no implicits are attempted

 

隐士转换发生的场景

conversions to an expected type

conversions of the receiver of a selection

implicit parameters

Scala - 隐士转换和隐式参数

原文:http://www.cnblogs.com/ayning/p/5756283.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!