mirror of
https://github.com/golang/go
synced 2024-11-23 07:10:05 -07:00
spec: add an example of a trivially invalid interface
In preparation for the forthcoming spec changes for #6977.
While at it, modernize existing File example that dates
back all the way to commit 18c5b488a3
.
Change-Id: Id10e4df0513e3de15bd58867222923eefa9473ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/187978
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
1ad64fafc8
commit
39d4178735
@ -1,6 +1,6 @@
|
|||||||
<!--{
|
<!--{
|
||||||
"Title": "The Go Programming Language Specification",
|
"Title": "The Go Programming Language Specification",
|
||||||
"Subtitle": "Version of May 14, 2019",
|
"Subtitle": "Version of July 31, 2019",
|
||||||
"Path": "/ref/spec"
|
"Path": "/ref/spec"
|
||||||
}-->
|
}-->
|
||||||
|
|
||||||
@ -1257,11 +1257,19 @@ non-<a href="#Blank_identifier">blank</a> name.
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
// A simple File interface
|
// A simple File interface.
|
||||||
interface {
|
interface {
|
||||||
Read(b Buffer) bool
|
Read([]byte) (int, error)
|
||||||
Write(b Buffer) bool
|
Write([]byte) (int, error)
|
||||||
Close()
|
Close() error
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<pre>
|
||||||
|
interface {
|
||||||
|
String() string
|
||||||
|
String() string // illegal: String not unique
|
||||||
|
_(x int) // illegal: method must have non-blank name
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
@ -1272,9 +1280,9 @@ have the method set
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
func (p T) Read(b Buffer) bool { return … }
|
func (p T) Read(p []byte) (n int, err error) { return … }
|
||||||
func (p T) Write(b Buffer) bool { return … }
|
func (p T) Write(p []byte) (n int, err error) { return … }
|
||||||
func (p T) Close() { … }
|
func (p T) Close() error { return … }
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
Reference in New Issue
Block a user