* d...@veryhaha.com [161013 08:42]:
> https://golang.org/ref/spec#Type_assertions
>
> 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
On Thu, 13 Oct 2016 10:38:16 -0700 (PDT)
d...@veryhaha.com wrote:
> https://golang.org/ref/spec#Type_assertions
>
> 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
> // illegal: strin
On Friday, October 14, 2016 at 1:33:52 AM UTC+8, di...@veryhaha.com wrote:
>
>
>
> 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
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, t
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 interfac
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 interfac
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
On Thursday, October 13, 2016 at 8:52:14 PM UTC+8, Jan Mercl wrote:
>
> On Thu, Oct 13, 2016 at 2:42 PM > 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
On Thu, Oct 13, 2016 at 2:42 PM 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 declar
https://golang.org/ref/spec#Type_assertions
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)
10 matches
Mail list logo