On Friday, October 14, 2016 at 1:28:01 AM UTC+8, di...@veryhaha.com wrote: > > > > On Thursday, October 13, 2016 at 11:22:14 PM UTC+8, Chris Manghane wrote: >> >> In that example y is a nil interface value of type l. The last line >> implies that for a type assertion to another interface type, the operation >> will only be possible if the underlying value implements both interfaces. >> That is, the value must have an m() method as well as all of io.reader >> methods or the type assertion will like the above assertion to a string >> type. >> > > But it looks it is not essential for the underlying value implements > io.Reader. > The code always compiles, whether or not the underlying value implements > io.Reader. > The difference is: > * if the underlying value implements io.Reader, then r is a non-nil > io.Reader value > * if the underlying value doesn't implement io.Reader, then r is a nil > io.Reader value >

## Advertising

sorry, my mistake, if the underlying value doesn't implement io.Reader, the last line will panic. > > >> >> On Oct 13, 2016 7:48 AM, <di...@veryhaha.com> wrote: >> >> >> >> On Thursday, October 13, 2016 at 8:52:14 PM UTC+8, Jan Mercl wrote: >> >>> On Thu, Oct 13, 2016 at 2:42 PM <di...@veryhaha.com> wrote: >>> >>> > I don't understand the comment of the last line. Can someone explain >>> it for me? >>> >>> "r has type io.Reader" means that the type if expr.(T) is T. >>> >>> "and y must implement both I and io.Reader" >>> >>> y is either nil or it implements I, because that's how it was declared >>> and nothing not implementing I can be assigned to it. The dynamic type of y >>> can implement any number of interfaces, so it can implement both I and >>> io.Reader. The later is checked at run time when the type assertion >>> expression y.(io.Reader) is actually evaluated. >>> >>> -- >>> >>> -j >>> >> >> So "y must implement both I and io.Reader" means short form of "the >> dynamic type of y must implement both I and io.Reader"? >> My brain really can't accept this short form. >> >> And in that example, it gives people the impression y is nil. I really >> think it is a bad example. >> >> >> >> >> >> >> I feel that comment (and that example) is very not professional for these >> reason: >> 1. y is a value of type I, >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> >> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.