From: Robert Griesemer nil.
-InterfaceType = "interface" "{" { MethodSpec ";" } "}" .
-MethodSpec = MethodName Signature | InterfaceTypeName .
+InterfaceType = "interface" "{" { ( MethodSpec | InterfaceTypeName ) ";" } "}" .
+MethodSpec = MethodName Signature .
MethodName = identifier .
InterfaceTypeName = TypeName .
-As with all method sets, in an interface type, each method must have a -unique -non-blank name. +An interface type may specify methods explicitly through method specifications, +or it may embed methods of other interfaces through interface type names.
@@ -1265,6 +1264,11 @@ interface {
}
++The name of each explicitly specified method must be unique +and not blank. +
+
interface {
String() string
@@ -1280,9 +1284,9 @@ have the method set
-func (p T) Read(p []byte) (n int, err error) { return ⦠}
-func (p T) Write(p []byte) (n int, err error) { return ⦠}
-func (p T) Close() error { return ⦠}
+func (p T) Read(p []byte) (n int, err error)
+func (p T) Write(p []byte) (n int, err error)
+func (p T) Close() error
@@ -1332,27 +1336,41 @@ as the File 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.
+embedding interface E in T.
+The method set of T is the union
+of the method sets of Tâs explicitly declared methods and of
+Tâs embedded interfaces.
-type ReadWriter interface {
- Read(b Buffer) bool
- Write(b Buffer) bool
+type Reader interface {
+ Read(p []byte) (n int, err error)
+ Close() error
}
-type File interface {
- ReadWriter // same as adding the methods of ReadWriter
- Locker // same as adding the methods of Locker
- Close()
+type Writer interface {
+ Write(p []byte) (n int, err error)
+ Close() error
}
-type LockedFile interface {
- Locker
- File // illegal: Lock, Unlock not unique
- Lock() // illegal: Lock not unique
+// ReadWriter's methods are Read, Write, and Close.
+type ReadWriter interface {
+ Reader // includes methods of Reader in ReadWriter's method set
+ Writer // includes methods of Writer in ReadWriter's method set
+}
+
+
+
+A union of method sets contains the (exported and non-exported)
+methods of each method set exactly once, and methods with the
+same names must
+have identical signatures.
+
+
+
+type ReadCloser interface {
+ Reader // includes methods of Reader in ReadCloser's method set
+ Close() // illegal: signatures of Reader.Close and Close are different
}