Java doesn't support pointers; are there any alternatives?
Note that I'm not referring to function pointers, but to pointers!
Java doesn't support pointers; are there any alternatives?
Note that I'm not referring to function pointers, but to pointers!
Well, pointers exist in C++ to allow a level of indirection when passing objects around so that an object can be modified or accessed in different areas of code. This is what happens by default in Java, but it approaches it in a different way. In Java, everything you have is a reference. The name you use to refer to an object is a reference to that object. When you call a function, that reference is copied into the function (passed by value). You can think of the variable names in Java as being similar to (or behaving like) pointers in C++.
Java does not have pointers. It has references almost exactly as C++ has.
Can't say alternative, but you can use references.
Edit:
More precisely, all Java invocations are pass-by-value. However, when you pass an object you are passing a reference by value. An ordinary Java parameter is more similar to a C++ reference than to C++ pass-by-value or pass-by-pointer.
Reference : Is Java “pass-by-reference”?
There are no pointers in Java. However Java uses references nearly everywhere which makes pointers close to obsolete.
Java references are very close to pointers.
Object x;
of java is close to a
void *x;
in C, or C++;