go语言的selector



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

时间: 2024-12-28 21:09:27

go语言的selector的相关文章

java脚本语言学习心得

第一篇技术博客,一定要认真! 第一篇技术博客,一定要认真! 第一篇技术博客,一定要认真! 好了,进入正题: 一 什么是脚本语言? 程序的运行方式有两种:编译运行和解释运行 1.1 前者的典型代表是java, 从文件角度看分为三步: write[编写]: a.java文件(拿个记事本就能写,扩展名是.java), compile[编译]: 编译(cmd命令是java a.java,ide集成了编译器运行之前自动编译)之后产生了a.class文件(是一堆二进制码,人看不懂,是给虚拟机看的) 运行[r

如何学好C语言

我相信,这可能是很多朋友的问题,我以前也有这样的感觉,编程编到一定的时候,发现能力到了瓶颈,既不深,也不扎实,半吊子.比如:你长期地使用Java和.NET ,这些有虚拟机的语言对于开发便利是便利,但是对于程序员来说可能并不太好,原因有两个: 虚拟机屏蔽了操作系统的系统调用,以及很多底层机制. 大量的封装好的类库也屏蔽了很多实现细节. 一段时间后,你会发现你知其然,不知所以然..我以前在CSDN上写过一篇<Java NIO类库Selector机制解析(上,下,续)>,在那篇文章中我说提到过(有讥

基于Swift语言开发微信、QQ和微博的SSO授权登录代码分析

前言 Swift 语言,怎么说呢,有一种先接受后排斥,又欢迎的感觉,纵观国外大牛开源框架或项目演示,Swift几乎占据了多半,而国内虽然出现很多相关技术介绍和教程,但是在真正项目开发中使用的占据很少部分,原因一是目前熟练它的开发者并不多,二是版本不太稳定,还需要更成熟可靠的版本支持,但总之未来还是很有前景的,深有体会,不管是代码量还是编译效率,以及语言特性,现代性都优于Object-C,估计后续会被苹果作为官方开发语言,值得期待. 走起 鉴于此,笔者将之前用Object-C写的SSO授权登录:微

iOS应用内切换多国语言

1.新建工程之类的就不用说了,配置项目本地化支持简体中文和英文 工程-PROJECT-info->Localizations,点"+",选择(Chinese(Simplified))添加简体中文,英文Xcode自带有(English),所以不需要再次添加.(点击添加弹出语言菜单,即可选择你所需要的语言) 2.现在可以开始添加多语言文件了. 注意:需要手动切换语言,而不是根据系统语言变换,所以命名不能与系统语言文件同名,即Localizable.strings: 自己随意命名,后缀

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

一.点语法 1> 基本使用 点语法本质上是set方法/get方法的调用 2> 使用注意 若出现在赋值操作符的右边,在执行时会转换成get方法 若出现在赋值操作符的左边,在执行时会转换成set方法 不能在set.get方法中用self使用点语法,会造成死循环 二.property和synthesize关键字 1> @property 作用 ① 自动生成某个成员变量的set方法和get方法 使用注意 ① 只能出现在@interface中 ② 可以使用逗号运算符为多个同类型的成员变量生成set

汇编1 ----C语言函数1

构造以下C程序并在合适位置插入breakpoints 在Visual Studio 2015 CTP6对其反汇编. 下面来分析 z = add(1, 2); 009C170E 6A 02 push 2 ????int z; ????z = add(1, 2); 009C1710 6A 01 push 1 009C1712 E8 8D FA FF FF call 009C11A4 009C1717 83 C4 08 add esp,8 009C171A 89 45 F8 mov dword ptr

OC语言基础

.h(头文件) .m(源文件c.oc) .mm(源文件c.oc.c++) gcc -c      -o    汇编 -framework Foundation链接  NS开头 字符串对象加@ oc中完全兼容c的函数库 NSLog可以自动换行,并且提供文件名编译时间等 需要包含头文件,每一个框架都有一个主头文件,其名字和主头文件相同,主头文件包含了这个框架的所有头文件. #import可以自动防止头文件重复包含. 链接时,需要手动连接框架. 10.多文件编译:所有对象都是以指针形式存在:跟c类似.

Java语言进阶过程(转)

[以下肯定是不完整的列表,欢迎补充] Java是一个通用的编程语言,其实可以干很多事,怎么学Java就看怎么用了. 但有一些一般的步骤: 1. 熟悉一种文本编辑器,比如Vim, Emacs, Notepad++, TextMate等.知道哪些是开源的,哪些是闭源的,哪些要收费.养成不用盗版软件的习惯. 2. 安装JDK(建议用你的Linux发行版自带的软件包管理器安装openjdk,过程中可能需要读发行版特定的文档) 3. 写一个Java的Hello world程序,并用命令行工具javac编译

初探swift语言的学习笔记十一(performSelector)

作者:fengsh998 原文地址:http://blog.csdn.net/fengsh998/article/details/35842441 转载请注明出处 如果觉得文章对你有所帮助,请通过留言或关注微信公众帐号fengsh998来支持我,谢谢! 在OC中使用好好的performSelector,但不知为什么在swift有意的被拿掉了.更有甚者连IMP, objc_msgSend也不能用了.虽然想不通为什么,但应该有他的道理.就不纠结了. 大家可能在OC中使用得更多的就是延时处理,及后台处