在golang中将var转换为接口{}时会发生什么?
我想弄清楚,当把一个变量转换成接口{}时,在golang下面发生了什么 我最近正在阅读golang/src/reflect/type.go的源代码,我不理解第1050行的代码,下面是代码:在golang中将var转换为接口{}时会发生什么?,go,Go,我想弄清楚,当把一个变量转换成接口{}时,在golang下面发生了什么 我最近正在阅读golang/src/reflect/type.go的源代码,我不理解第1050行的代码,下面是代码: // Create a new ptrType starting with the description // of an *unsafe.Pointer. p = new(ptrType) var iptr interface{} = (*unsafe.Pointer)(nil) prototype :=
// Create a new ptrType starting with the description
// of an *unsafe.Pointer.
p = new(ptrType)
var iptr interface{} = (*unsafe.Pointer)(nil)
prototype := *(**ptrType)(unsafe.Pointer(&iptr))
*p = *prototype
我认为关键是将数据分配给接口{}的行为,有人能帮忙吗?似乎适合我在中提到的指针中的两个值。这不是理解接口的最佳方式。你可能想看看。这可能不再在所有情况下或所有平台上都是完全准确的,但肯定会给您带来更多启发,而不仅仅是浏览PackageReflect的源代码。