diff options
author | Robert Griesemer <gri@golang.org> | 2014-09-25 12:49:42 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2014-09-25 12:49:42 -0700 |
commit | 59ab5d9895fb06611f705763b127ae2982ce258f (patch) | |
tree | ee7c5d0320b54b68a599e268282ca3cfb5d2d1f1 /doc | |
parent | 48436631aaf288efa2d65a9f27816482ff8e17a5 (diff) | |
download | go-59ab5d9895fb06611f705763b127ae2982ce258f.tar.gz |
spec: clarify embedding of interfaces
Fixes issue 7886.
LGTM=iant, r, rsc
R=r, iant, rsc, ken
CC=golang-codereviews
https://codereview.appspot.com/149010043
Diffstat (limited to 'doc')
-rw-r--r-- | doc/go_spec.html | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index 7d86ca863..e0ed7e7b7 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ <!--{ "Title": "The Go Programming Language Specification", - "Subtitle": "Version of September 19, 2014", + "Subtitle": "Version of September 25, 2014", "Path": "/ref/spec" }--> @@ -1154,11 +1154,11 @@ interface{} <p> Similarly, consider this interface specification, which appears within a <a href="#Type_declarations">type declaration</a> -to define an interface called <code>Lock</code>: +to define an interface called <code>Locker</code>: </p> <pre> -type Lock interface { +type Locker interface { Lock() Unlock() } @@ -1174,28 +1174,35 @@ func (p T) Unlock() { … } </pre> <p> -they implement the <code>Lock</code> interface as well +they implement the <code>Locker</code> interface as well as the <code>File</code> interface. </p> + <p> -An interface may use an interface type name <code>T</code> -in place of a method specification. -The effect, called embedding an interface, -is equivalent to enumerating the methods of <code>T</code> explicitly -in the interface. +An interface <code>T</code> may use a (possibly qualified) interface type +name <code>E</code> in place of a method specification. This is called +<i>embedding</i> interface <code>E</code> in <code>T</code>; it adds +all (exported and non-exported) methods of <code>E</code> to the interface +<code>T</code>. </p> <pre> -type ReadWrite interface { +type ReadWriter interface { Read(b Buffer) bool Write(b Buffer) bool } type File interface { - ReadWrite // same as enumerating the methods in ReadWrite - Lock // same as enumerating the methods in Lock + ReadWriter // same as adding the methods of ReadWriter + Locker // same as adding the methods of Locker Close() } + +type LockedFile interface { + Locker + File // illegal: Lock, Unlock not unique + Lock() // illegal: Lock not unique +} </pre> <p> |