Java有指针吗? [英] Does Java have pointers?

查看:107
本文介绍了Java有指针吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果Java没有指针,那么 new 关键字在Java中的作用是什么?

If Java does not have pointers, then what does the the new keyword do in Java?

推荐答案

正如所指出的,Java有参考。这些有何不同?

As pointed out, Java has references. How are these different ?


  1. 您无法对这些操作执行算术运算或其他此类操作

  2. 它们不指向包含对象的内存(即它们不是另一个名称的指针)。 JVM可以自由地在VM内存中移动对象,并且很可能在垃圾收集期间执行。然而,引用仍指向该对象,尽管它在内存中移动。

  1. you can't perform arithmetic or other such operations on these
  2. they do not point to the memory containing the object (i.e. they are not pointers by another name). The JVM is at liberty to move objects around within the VM memory, and most likely will do during garbage collection. The references however still point to that object, despite its movement within memory.

因此它们不像C ++引用(直接指向一个东西)。或许更好的名称是句柄

So they're not like C++ references (pointing directly to an object). Perhaps a better name would be handle.

这篇关于Java有指针吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆