golang interface 类型学习

接口类型变量的内存结构

动态类型  动态值

对于动态类型指的是当其他非接口类型变量赋值给接口类型变量时,接口类型变量中的动态类型就是当前非接口类型

对于动态值指的就是当其他非接口类型变量赋值给接口类型变量时,接口类型变量中的动态值就是当前非接口类型变量值的副本

对于接口变量对应的就是runtime2.go中的iface

type iface struct {
	tab  *itab
	data unsafe.Pointer
}

  

对于接口类型变量和接口实现类型变量对比,如果接口类型变量的动态类型和接口实现类型一致,则直接对比当前接口变量动态值和实现类型变量值

https://golang.google.cn/ref/spec#Comparison_operators

A value x of non-interface type X and a value t of interface type T are comparable when values of type X are comparable and X implements T. They are equal if t's dynamic type is identical to X and t's dynamic value is equal to x.

 

对于变量之间的赋值操作,对于A = B,实际是将B的副本赋值给A

 

 

 

posted @ 2020-08-25 10:43  郭星  阅读(302)  评论(0)    收藏  举报