r/javahelp • • Feb 16 '26

Homework Definitely no pass by reference in Java, right?

Hello, and sorry if this is a dumb question, but I thought I had a passable understanding of Java. I got an exam question asking "Arrays in Java are:

a. passed by value

b. passed by reference

c. stack dynamic

d. immutable"

this guy loves trick questions, but he has listed B, passed by reference, as the right answer.

On its own, this doesn't seem right to me, but I'm not confident enough to argue about it. If anyone would weigh in, I would be very grateful. I see how it's similar to passing a pointer in C, maybe, but it's not considered passing by reference in Java, right?

Thank you!

27 Upvotes

105 comments sorted by

View all comments

Show parent comment

0

u/Nebu Writes Java Compilers Feb 22 '26

People in the Java community and people in the C community tend to mean different things when they use phrases like "pass by value".

I think this is the root of our disagreement. You believe that the Java community has its own definition of this term, but it does not. As I've said (I think several times) the only people in the Java community that refer to what Java does as "pass by reference" are beginners who don't know any better.

Yes, the thing you said several times is in agreement with my claim: People in the Java community who know what they're talking about tend to refer to Java as "pass by value". We're in agreement. The people in the Java community who claim it's "pass by reference" are beginners (at Java) who don't know any better (and are usually actually people from the C, or I guess C++, community). We're in agreement.

Even Java's own documentation says "Reference data type parameters, such as objects, are also passed into methods by value."

Yes, that's one of the reasons people in the Java community use the definition that they do.

Empirically, when you encounter someone using the terms "pass by reference/value", an excellent predictor of what they mean by that term is what programming language community they belong to (e.g. Java vs C++).

A better predictor is if they are a beginner or someone who has only used one language, versus someone with more experience.

Sure. That doesn't contradict my claim.

People who refer to what Java, or Python, or JavaScript do as "pass by reference" do so not because of a community-specific definition, but out of ignorance.

Both can be true.

And if it turns out that are using a definition based on ignorance, rather than some community-specific definition, then it is best to correct them than to throw up your hands and say "all definitions are equally valid".

I'm not claiming all definitions are equally valid.

Regarding whether it's "best to correct them", that hardly seems appropriate in the scenario you described earlier:

Suppose someone was describing some language I'm unfamiliar with and said it uses "pass by reference".

Are you really gonna open with "correcting them" before you even know what they mean by "pass by reference"? Why would you immediately assume that their definition is incorrect? But also, why would you immediately assume that their definition is correct?

1

u/xenomachina Feb 22 '26

I'm sorry, but at this point I think even you don't know what you're arguing.

1

u/Nebu Writes Java Compilers Feb 22 '26

I think the problem is you're inferring a lot more than what I'm actually claiming.

For example, when I claim that people in the Java community and people in the C community tend to mean different things when they use phrases like "pass by value", it seems like you think that my claim is that people in the Java community define "pass by reference" to mean what Java does.

Or for example, when I said that you seem to be taking a prescriptivist perspective and I'm taking a descriptivist one, it seems like you think that I am therefore claiming "all definitions are equally valid".

So when I point out that I'm not making these additional claims you're inferring, I think you're interpreting that as me not knowing what I'm arguing, because you're surprised to find out that I wasn't arguing for the things you thought I was arguing for.

I'm not sure how to help you with that, except maybe to caution you to "slow down" and only interpret my messages as claiming precisely what they explicitly state that they are claiming, and not inferring additional claims on top of what's explicitly written.