When I going through java tutorials I got an idea about the pointers are not used in java. but java internally uses pointers, but when we look through developer perspective java supports references only. Then why java does not support pass by reference?
Asked
Active
Viewed 48 times
2 Answers
3
All object variables are just references, so when you pass an object you're actually passing by reference (technically you're passing a reference variable which gets copied by value). The only things that are passed by value are primitive types like int.

Duncan Thacker
- 5,073
- 1
- 10
- 20
-
Cannot agree with "All objects are just references", but can agree "All object variables are just references" – Jacek Cz Sep 08 '17 at 13:52
-
...ok, I'll edit it. – Duncan Thacker Sep 08 '17 at 13:55
-
I find your answer misleading, you said only primitives are passed by value. "References" to objects instance are pass by value. Or you would be able to reinstanciate a parameter in a method to that reference. This subject requires a lot of explanation to be complete. – AxelH Sep 08 '17 at 14:00
-
I don't think the questioner requires a complete and fully detailed answer, and I did address your issue in my parenthetical. Feel free to give a full explanation if you like, but I suspect it is not what is needed here! – Duncan Thacker Sep 08 '17 at 14:01
-
@DuncanThacker that's because you opened the problem without going into the explanation that bother me. Well I already address my explanation by flagging the duplicate actually ;) – AxelH Sep 08 '17 at 14:09
-
@DuncanThacker thanks for your comment. Actually that was what I need. :-) – Aparna Navaprabhan Sep 08 '17 at 15:32
0
Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value.
How to do the equivalent of pass by reference for primitives in Java

DoesData
- 6,594
- 3
- 39
- 62
-
Well, you could just post a comment to point the duplicate (or flag the question if you can), there is no point to recreate a new question thread about this. (especially with a question with +4500 upvotes) – AxelH Sep 08 '17 at 13:57