]> Cypherpunks repositories - gostls13.git/commitdiff
spec: slightly more realistic example for type assertions
authorRobert Griesemer <gri@golang.org>
Wed, 19 Oct 2016 16:56:53 +0000 (09:56 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 19 Oct 2016 17:16:55 +0000 (17:16 +0000)
For #17428.

Change-Id: Ia902b50cf0c40e3c2167fb573a39d328331c38c7
Reviewed-on: https://go-review.googlesource.com/31449
Reviewed-by: Ian Lance Taylor <iant@golang.org>
doc/go_spec.html

index 5243ec6dad8cf74a1e4e0f4c11710b4725d781ac..ee3a8457f20d2bcbc659b4f513ec91ddf6532e49 100644 (file)
@@ -1,6 +1,6 @@
 <!--{
        "Title": "The Go Programming Language Specification",
-       "Subtitle": "Version of October 18, 2016",
+       "Subtitle": "Version of October 19, 2016",
        "Path": "/ref/spec"
 }-->
 
@@ -3116,13 +3116,16 @@ known to be <code>T</code> in a correct program.
 </p>
 
 <pre>
-var x interface{} = 7  // x has dynamic type int and value 7
-i := x.(int)           // i has type int and value 7
+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>