What is the difference between pointers and reference variables in Java?
•
Java
My java book explains that to use objects, we can assign them to reference variables How is it different from a pointer to an object? Does java have pointers?
Thank you:)
Solution
A reference is something like a pointer. You can't perform arithmetic on... Although it's more opaque Although the bottom bits may be addresses in virtual memory, they are not necessarily They are just a way to get objects (or represent null values) So when they're not exactly the same, if you're used to seeing a pointer as a way to "identify an object or navigate to it" (in a sense), yes, these ideas also apply to references
Java does not have such pointers (unlike C #, which has references and pointers - the latter is used in "unsafe" code)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码