Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在golang中将var转换为接口{}时会发生什么?_Go - Fatal编程技术网

在golang中将var转换为接口{}时会发生什么?

在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 :=

我想弄清楚,当把一个变量转换成接口{}时,在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 := *(**ptrType)(unsafe.Pointer(&iptr))
*p = *prototype

我认为关键是将数据分配给接口{}的行为,有人能帮忙吗?

似乎适合我在中提到的指针中的两个值。这不是理解接口的最佳方式。你可能想看看。这可能不再在所有情况下或所有平台上都是完全准确的,但肯定会给您带来更多启发,而不仅仅是浏览PackageReflect的源代码。