Commit 023bb034 authored by Robert Griesemer's avatar Robert Griesemer

spec: slightly more realistic example for type assertions

For #17428.

Change-Id: Ia902b50cf0c40e3c2167fb573a39d328331c38c7
Reviewed-on: https://go-review.googlesource.com/31449Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 1e3dc3d5
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Version of October 18, 2016",
"Subtitle": "Version of October 19, 2016",
"Path": "/ref/spec"
}-->
......@@ -3120,9 +3120,12 @@ var x interface{} = 7 // x has dynamic type int and value 7
i := x.(int) // i has type int and value 7
type I interface { m() }
var y I
s := y.(string) // illegal: string does not implement I (missing method m)
r := y.(io.Reader) // r has type io.Reader and y must implement both I and io.Reader
func f(y I) {
s := y.(string) // illegal: string does not implement I (missing method m)
r := y.(io.Reader) // r has type io.Reader and the dynamic type of y must implement both I and io.Reader
}
</pre>
<p>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment