For a primary expression x
, which is a package name, the selector expression
X.f
denotes the field or method of the f
value x
(or sometimes *x
; see below). The identifier is f
called the (field or method) selector; it must isn't 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 may f
denote a field or method f
of a type T
, or it could refer to a field or method of f
a Neste D anonymous field of T
. The number of anonymous fields traversed to reach are f
called their depth in T
. The depth of a field or method f
declared is T
zero. The depth of a field or method declared in an anonymous field in are the depth of in f
A
T
f
A
PLU S one.
The following rules apply to selectors:
- For a value
x
of type T
or *T
where T
was not a interface type, x.f
denotes the field or method at the SH Allowest depth in T
where there are such an f
. If There is not exactly one f
with shallowest depth, the selector expression is illegal.
- For a variable
x
of type I
where I
was an interface type, x.f
denotes the actual method with name f
of The value assigned to x
. If there is no method f
I
with a name in the method set of, the selector expression is illegal.
- In all and cases, is
x.f
illegal.
- If
x
is of pointer type and have the value nil
x.f
and denotes a struct field, assigning to or evaluating x.f
Cau SES a run-time panic.
- If
x
is of interface type and have the value nil
, calling 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, was x.y
shorthand for (*x).y
; if the field y
was also a pointer to a struct, x.y.z
I s shorthand (*(*x).y).z
for, and so on. If x
contains an anonymous field of type *A
, where was A
also a struct type, is x.f
shorthand for (*x.A).f
.
Original Http://golang.org/ref/spec#Selectors
Selector of the Go language