why is golang interface internally an int

blov · · 454 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>This is totally different from java. I&#39;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?</p> <hr/>**评论:**<br/><br/>Sythe2o0: <pre><p>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&#39;s a pointer to a type and a value. </p></pre>kostix: <pre><p>Please read this go-to article — <a href="https://research.swtch.com/interfaces" rel="nofollow">&#34;Go Data Structures: Interfaces&#34;</a> by Russ Cox.</p> <p>Note that it in the up-to-date &#34;reference&#34; implementation of Go (there are many in fact) &#34;short&#34; values (those which are less-than-or-equal to the size of the platform&#39;s pointer) are no longer cached in the interface values but this is an implementation detail you should safely ignore.</p></pre>paul2048: <pre><p>Cause it&#39;s a pointer?</p></pre>nemith: <pre><p>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.</p></pre>

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

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