why is golang interface internally an int

blov · 2017-09-13 06:00:08 · 646 次点击    
这是一个分享于 2017-09-13 06:00:08 的资源,其中的信息可能已经有所发展或是发生改变。

This is totally different from java. I've read many articles, but seems like none of them dealing with the design purpose. Is there a TL;DR version of why is this?


评论:

Sythe2o0:

Where did you get the impression that an interface was an int? As a datatype, an interface is a collection of functions. In implementation, it's a pointer to a type and a value.

kostix:

Please read this go-to article — "Go Data Structures: Interfaces" by Russ Cox.

Note that it in the up-to-date "reference" implementation of Go (there are many in fact) "short" values (those which are less-than-or-equal to the size of the platform's pointer) are no longer cached in the interface values but this is an implementation detail you should safely ignore.

paul2048:

Cause it's a pointer?

nemith:

At some point all values in a computer is just a number. In this case it would probably be a pointer to a memory location.


入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

646 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传