Java中的指针和引用变量有什么区别? [英] What is the difference between a pointer and a reference variable in Java?

查看:960
本文介绍了Java中的指针和引用变量有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java书解释说,要使用对象,我们可以将它们分配给引用变量。这与指向对象的指针有什么不同? Java有指针吗?

My Java book explains that to use objects, we can assign them to reference variables. How is that different from a pointer to an object? Does Java have pointers?

谢谢:)

推荐答案

参考有点像指针,你不能做算术...虽然它更不透明。虽然底层位可能是虚拟内存中的地址,但它们不一定是。它们只是获取对象(或表示空值)的一种方式。因此,虽然它们并不完全相同,但如果您习惯将指针视为识别对象或导航到它的方式(在某种意义上),那么是的,这些想法也适用于引用。

A reference is sort of like a pointer that you can't do arithmetic on... although it's more opaque. While the underlying bits may be an address in virtual memory, they don't have to be. They're just a way of getting to an object (or representing the null value). So while they're not exactly the same, if you're used to thinking of a pointer as "a way of identifying an object or navigating to it" (in some sense) then yes, those thoughts apply to references too.

Java没有这样的指针(不像C#,它有引用指针 - 后者用于不安全代码) 。

Java doesn't have pointers as such (unlike, say, C# which has references and pointers - the latter being used in "unsafe" code).

这篇关于Java中的指针和引用变量有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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