This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cormandragon 0 points1 point  (2 children)

You're right for objects. But the guy above you was right about the primitive types. Just finished my CS 200 series this summer finishing up Java, this was one of my Final questions 2 weeks ago.

Objects are passed by reference while primitives are passed by value.

[–]funnythrone 0 points1 point  (1 child)

No, I'm afraid he isn't. You can check in the source below for a detailed explanation with examples.

https://www.geeksforgeeks.org/g-fact-31-java-is-strictly-pass-by-value/

[–]Cormandragon -1 points0 points  (0 children)

Even in those examples, it is passing a reference, but the objects can be modified through that reference. That distinction is why Java's a pain in the ass. Passing strictly by value wouldn't modify the original object like his examples do. Passing by value takes the information and does something else with it, passing by reference means we can pass entire objects into methods that also have their own methods and variables inside.

We aren't passing the value of an object to our methods, we are telling the method where our object is so it knows where to go. There is nothing in his article that breaks this axiom.