From 59ab5d9895fb06611f705763b127ae2982ce258f Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 25 Sep 2014 12:49:42 -0700 Subject: 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 --- doc/go_spec.html | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'doc') 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 @@ @@ -1154,11 +1154,11 @@ interface{}

Similarly, consider this interface specification, which appears within a type declaration -to define an interface called Lock: +to define an interface called Locker:

-type Lock interface {
+type Locker interface {
 	Lock()
 	Unlock()
 }
@@ -1174,28 +1174,35 @@ func (p T) Unlock() { … }
 

-they implement the Lock interface as well +they implement the Locker interface as well as the File interface.

+

-An interface may use an interface type name T -in place of a method specification. -The effect, called embedding an interface, -is equivalent to enumerating the methods of T explicitly -in the interface. +An interface T may use a (possibly qualified) interface type +name E in place of a method specification. This is called +embedding interface E in T; it adds +all (exported and non-exported) methods of E to the interface +T.

-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
+}
 

-- cgit v1.2.1