该可转让规则是宽容的,这导致另一种可能性,你可以保留的原始定义匿名类型
A写入,同时允许该类型的短复合文字。如果您确实坚持使用该
B字段的匿名类型,那么我可能会写类似以下内容:
package mainimport "fmt"type ( A struct { B struct { Some string Len int } } b struct { Some string Len int })func main() { a := &A{b{"xxx", 3}} fmt.Printf("%#vn", a)}操场
输出量
&main.A{B:struct { Some string; Len int }{Some:"xxx", Len:3}}


