goroutine

goroutine
goroutine
goroutine
goroutine
goroutine
goroutine
goroutine

goroutine

channel可以是各种数据类型:
goroutine
(map类型)
goroutine
(struct类型)
goroutine
(接口类型)
goroutine
goroutine

package main

import "fmt"

type student struct {
    name string
}

func main() {
    var stuChan chan interface{}
    //空interface类型可以是任意类型
    stuChan = make(chan interface{}, 10)
    stu := student{name:"stu01"}
    stuChan <- &stu

    var stu01 interface{}
    stu01 = <- stuChan

    fmt.Println(stu01)

    var stu02 *student
    //将stu01由interface转换为结构体类型指针
    stu02, ok := stu01.(*student)
    if !ok {
        fmt.Println("不可以转换")
        return
    }
    fmt.Println(stu02)

}

输出:
&{stu01}
&{stu01}

Process finished with exit code 0

上一篇:goroutine/channel(select、定时器)


下一篇:Zabbix报告无交换内存主机 Lack of free swap space on xxxxx