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

查看:23
本文介绍了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++ 引用(直接指向一个对象).或许更好的名字是handle.

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

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

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