企业网站源码自适应,WordPress强制分享插件,全网维护,现代建设中国公司网站定义说明
静态类型#xff08;static type#xff09;#xff1a;在编码时就能确定的类型#xff0c;通过变量定义可以确定的类型#xff1b;动态类型#xff08;concrete type#xff09;#xff1a;在运行时才能确定具体的数据类型#xff1b;
动态静态类型如何理…定义说明
静态类型static type在编码时就能确定的类型通过变量定义可以确定的类型动态类型concrete type在运行时才能确定具体的数据类型
动态静态类型如何理解
go 语言中interfaceany可以承接所有类型的数据所以这部分只有具体运行的时候才能确定数据具体类型 var i interface{}var num int 1var str string hello worldi numi str在该示例中第一行声明了一个interface的变量i在编码时就可以确定了所以i的静态类型就是interface; 同理第二行num的静态类型为int,第三行str的静态类型为string 第四行把num赋值给inum的实际类型是int, 所以此时i的动态类型就是int 第五行把str赋值给inum的实际类型是string所以此时i的动态类型就是string
Golang 中的interface的底层延申
golang 中interface有两种含义/用法
常规的接口类型有一些带实现的接口定义表示任意数据类型any
golang 的底层实现也是根据这两种情况做了不同的实现底层分别对应iface和eface
// 空接口结构
type eface struct {_type *_type // 实体类型data unsafe.Pointer // 数据地址
}// 包含方法的结构
type iface struct {tab *itab // 接口和实体类型data unsafe.Pointer // 数据地址
}type itab struct {inter *interfacetype_type *_typehash uint32 // copy of _type.hash. Used for type switches._ [4]bytefun [1]uintptr // variable sized. fun[0]0 means _type does not implement inter.
}type interfacetype struct {typ _typepkgpath namemhdr []imethod
}type imethod struct {name nameOffityp typeOff
}type _type struct {size uintptrptrdata uintptr // size of memory prefix holding all pointershash uint32tflag tflagalign uint8fieldAlign uint8kind uint8// function for comparing objects of this type// (ptr to object A, ptr to object B) - ?equal func(unsafe.Pointer, unsafe.Pointer) bool// gcdata stores the GC type data for the garbage collector.// If the KindGCProg bit is set in kind, gcdata is a GC program.// Otherwise it is a ptrmask bitmap. See mbitmap.go for details.gcdata *bytestr nameOffptrToThis typeOff
}type nameOff int32
type typeOff int32
type tflag uint8