For a primary expression x that is not a package name, the selector expression

x.f

denotes the field or method f of the value x (or sometimes *x; see below). The identifier f is called the (field or method) selector; it must not be the blank identifier. The type of the selector expression is the type of f. If x is a package name, see the section on qualified identifiers.

A selector f may denote a field or method f of a type T, or it may refer to a field or method f of a nested anonymous field of T. The number of anonymous fields traversed to reachf is called its depth in T. The depth of a field or method f declared in T is zero. The depth of a field or method f declared in an anonymous field A in T is the depth of f in A plus one.

The following rules apply to selectors:

  1. For a value x of type T or *T where T is not an interface type, x.f denotes the field or method at the shallowest depth in T where there is such an f. If there is not exactly one fwith shallowest depth, the selector expression is illegal.
  2. For a variable x of type I where I is an interface type, x.f denotes the actual method with name f of the value assigned to x. If there is no method with name f in the method set of I, the selector expression is illegal.
  3. In all other cases, x.f is illegal.
  4. If x is of pointer type and has the value nil and x.f denotes a struct field, assigning to or evaluating x.f causes a run-time panic.
  5. If x is of interface type and has the value nilcalling or evaluating the method x.f causes a run-time panic.

Selectors automatically dereference pointers to structs. If x is a pointer to a struct, x.y is shorthand for (*x).y; if the field y is also a pointer to a struct, x.y.z is shorthand for (*(*x).y).z, and so on. If x contains an anonymous field of type *A, where A is also a struct type, x.f is shorthand for (*x.A).f.

原文 http://golang.org/ref/spec#Selectors


go语言的selector的更多相关文章

  1. objective-c中的@selector()和 c /c++的函数指针

    先看tomcat里用到的代码: //然后开始动画 //把图片放到animationImages,接受数组参数 self.tom.animationImages = arrayImage; //设置时间 ...

  2. R语言爬虫初尝试-基于RVEST包学习

    注意:这文章是2月份写的,拉勾网早改版了,代码已经失效了,大家意思意思就好,主要看代码的使用方法吧.. 最近一直在用且有维护的另一个爬虫是KINDLE 特价书爬虫,blog地址见此: http://w ...

  3. 黑马程序员——OC语言基础语法 面向对象的思想

    Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结)(一)基础语法 1)关键字 @interface.@implementati ...

  4. 【转】浅思OC的语言特性

    算了算,学习IOS已经有一段时间了.今天花了点时间思考一下OC的语言特性,让自己的心不要那么浮躁,注重基础,回归本源. OC做为一门面向对象语言,自然具有面向对象的语言特性,如封装.继承.多态.他具有 ...

  5. [Java面试九]脚本语言知识总结.

    核心内容概述 1.JavaScript加强,涉及到ECMAScript语法.BOM对象.DOM对象以及事件. 2.Ajax传统编程. 3.jQuery框架,九种选择器为核心学习内容 4.JQuery ...

  6. XML学习笔记6——XPath语言

    在上一篇笔记的结尾,我们接触到了两个用于选择XML文档中特定范围的元素<selector>和<field>,这两个元素的取值都是XPath表达式,那么,什么是XPath呢?简单 ...

  7. 如何设置unobtrusive的语言包

    场景:网站是用的validate.unotrusive.js验证的,网站的语言已经切换到繁体了,但是提示语言还是英文. 环境:asp.net mvc4,jquery.validate.unotrusi ...

  8. OC语言description方法和sel

    OC语言description方法和sel 一.description方法 Description方法包括类方法和对象方法.(NSObject类所包含) (一)基本知识 -description(对象 ...

  9. OC语言-04-OC语言-核心语法

    一.点语法 1> 基本使用 点语法本质上是set方法/get方法的调用 2> 使用注意 若出现在赋值操作符的右边,在执行时会转换成get方法 若出现在赋值操作符的左边,在执行时会转换成se ...

随机推荐

  1. 影响性能的关键部分-ceph的osd journal写

    在前面一篇文章中,我们看到,当使用filestore时,osd会把磁盘分成data和journal两部分.这主要是为了支持object的transaction操作.我的想法是,ceph需要具有数据保护 ...

  2. HTML input="file" 浏览时只显示指定文件类型 xls、xlsx、csv

    html input="file" 浏览时只显示指定文件类型 xls.xlsx.csv <input id="fileSelect" type=" ...

  3. mfc 控件字体设置

    将以下代码加入至 OnInitDialog() 中 // TODO: Add extra initialization here CFont * m_font= new CFont; m_font-& ...

  4. 项目中Zookeeper配置参数笔记

    ZooKeeper是以Fast Paxos算法为基础的,Paxos 算法存在活锁的问题,即当有多个proposer交错提交时,有可能互相排斥导致没有一个proposer能提交成功,而Fast Paxo ...

  5. Frameset的使用

    一.frameset 1. 属性 ①border 设置框架的边框粗细. ②bordercolor 设置框架的边框颜色. ③frameborder 设置是否显示框架边框.设定值只有0.1:0 表示不要边 ...

  6. Win8.1安装Visual Studio 2015提示需要KB2999226

    http://www.microsoft.com/zh-cn/download/details.aspx?id=48234 ,下载解压出来就有了,里面包含Vista.Win7.Win8.1三个系统x8 ...

  7. 尚学堂Spring视频教程(二):Spring控制反转

    用Spring来实现IOC 在上节中我们自定义了一个接口BeanFactory和类ClassPathXmlApplicationContext来模拟Spring,其实它们在Spring中确实是存在的, ...

  8. 如何去除My97 DatePicker控件上右键弹出官网的链接

    http://my97.net/dp/My97DatePicker/calendar.js?最后结尾处: 这个就是官网链接地址了. 然后查找 net,nte,ent,etn,ten,tne最终找到了“ ...

  9. oracle中having的用法

    having的用法,having一般是用在group的后面,用在前面查询结果相同,但是语法上不通顺.答:having是对行组进行过滤.一般是先用where 过滤返回行,用group by 对过滤后的行 ...

  10. (转)You might not need jQuery

    You might not need jQuery You certainly can support IE 9 and below without jQuery, but we don't. Ple ...