ZhangZhihui's Blog  

 

package main

import (
    "fmt"
)

type A struct {
    field1 string
}

type B struct {
    field1 string
}

func main() {
    a := A{
        field1: "aaa",
    }

    b := B(a)

    fmt.Printf("%#v\n", b)
}

 

zzh@ZZHPC:~/zd/Github/ztest$ go run main.go
main.B{field1:"aaa"}

 

A and B must have same fields (equal fields number, same names, same types).

posted on 2024-11-15 16:30  ZhangZhihuiAAA  阅读(2)  评论(0编辑  收藏  举报