zhyq0826/zhyq0826.github.io

Go interface 详解 (四) :类型断言 | 三月沙

Opened this issue · 2 comments

Go interface 详解 (四) :类型断言 | 三月沙

本系列是阅读 “The Go Programming Language” 理解和记录。 Type AssertionType assertion(断言)是用于 interface value 的一种操作,语法是 x.(T),x 是 interface type 的表达式,而 T 是 assertd type,被断言的类型。 断言的使用主要有两种情景: 如果 asserted type 是一个

http://sanyuesha.com/2017/12/01/go-interface-4/

case 1 and case 2 have the same result as follows:

hello Go!*os.File
*os.File

The result is different from your statement above. Please double check. Thanks a lot!

@rockyhwang 输出的值一样,但是 case 2 中 rw 仍然是一个 interface,%T 确实只输出了实际的 dynamic type 的 value