Created
February 25, 2014 18:20
-
-
Save bgnori/9214691 to your computer and use it in GitHub Desktop.
型アサーション(type assertion) と chan
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
type chanS interface{ | |
Type() reflect.Type | |
} | |
func main() { | |
ch1 := make(chan int) | |
go func() { | |
for i := 0; i < 10; i++{ | |
ch1<- i | |
} | |
close(ch1) | |
}() | |
for v := range ch1 { | |
fmt.Println(v) | |
} | |
s, ok := ch1.(chanS) | |
fmt.Println(ok) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prog.go:26: invalid type assertion: ch1.(chanS) (non-interface type chan int on left) | |
[process exited with non-zero status] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
via http://mattn.kaoriya.net/software/lang/go/20130919023425.htm