GO
wending-Y
这个作者很懒,什么都没留下…
展开
-
GO 反射
反射 反射的概念在Java中也存在,无非就是程序动态得到字段,字段值 下面是GO语言的实现 import ( "fmt" "reflect" ) func main() { type T struct { A int B string } t := T{23, "skidoo"} //反射 s := reflect.ValueOf(&t).Elem() typeOfT := s.Type() for i := 0; i < s.NumField(); i++ {原创 2020-05-30 11:48:49 · 125 阅读 · 0 评论 -
GO chan
管道 Go语言提倡使用通信的方法代替共享内存 代码 import "fmt" func sum(s []int, c chan int) { sum := 0 for _, v := range s { sum += v } //计算得到的数组的值,把值发送到管道 c <- sum // send sum to c } func main() { s := []int{7, 2, 8, -9, 4, 0} //定义一个整形管道 c := make(chan int) go原创 2020-05-29 21:57:32 · 356 阅读 · 0 评论 -
GO 实现 interface
接口实现 go语言中的接口实现是一种隐式实现 import "fmt" type Say interface { sayhello() saybye() } func (t people) sayhello() { fmt.Println("hello") } // people这个struct 实现Say接口的 saybye方法 func (t people) saybye() { fmt.Println("bye") } type people struct { age int原创 2020-05-29 19:55:57 · 878 阅读 · 0 评论