加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

我们可以在Java中添加结构吗?

发布时间:2020-12-15 04:13:50 所属栏目:Java 来源:网络整理
导读:我在接受采访时被问到这个问题并且无法回答.希望您能够帮助我. 问题是:为什么Java人员不添加对结构的支持?为什么不可能将堆栈上分配的值类型添加到Java? 我想以前的java版本应该存在一些向后兼容性问题?但是,我无法提出任何问题. 解决方法 虽然Java不允
我在接受采访时被问到这个问题并且无法回答.希望您能够帮助我.

问题是:为什么Java人员不添加对结构的支持?为什么不可能将堆栈上分配的值类型添加到Java?

我想以前的java版本应该存在一些向后兼容性问题?但是,我无法提出任何问题.

解决方法

虽然Java不允许堆栈分配,但它确实使用了一些名为Escape Analysis的东西.

找到了一个触及这个的链接:http://www.ibm.com/developerworks/java/library/j-jtp09275/index.html

The Java language does not offer any way to explicitly allocate an object on the stack,but this fact doesn’t prevent JVMs from still using stack allocation where appropriate. JVMs can use a technique called escape analysis,by which they can tell that certain objects remain confined to a single thread for their entire lifetime,and that lifetime is bounded by the lifetime of a given stack frame. Such objects can be safely allocated on the stack instead of the heap. Even better,for small objects,the JVM can optimize away the allocation entirely and simply hoist the object’s fields into registers.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读