What is the difference between a pointer and a reference variable in Java?

后端 未结 9 1619
南笙
南笙 2020-11-28 15:42

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?

T

9条回答
  •  旧巷少年郎
    2020-11-28 16:22

    A reference is a pointer that you can't normally see the value of (i.e., the memory address). The only operations allowed are to set it (from another reference) and to reference through it to the referred-to object. It can be set from a reference-valued expression, such as the new operator, or from another reference (which is syntactically a simple reference-valued expression).

提交回复
热议问题