Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:26:33+00:00 2026-05-26T23:26:33+00:00

And who has the authority to decide? Edit: Apparently I haven’t succeeded in formulating

  • 0

And who has the authority to decide?

Edit: Apparently I haven’t succeeded in formulating my question well.
I am not asking how Java’s argument passing works. I know that what looks like a variable holding an object is actually a variable holding a reference to the object, and that reference is passed by value.
There are lots of fine explanations of that mechanism here (in the linked threads and others) and elsewhere.

The question is about the technical meaning of the term pass-by-reference. (End edit)

I am not sure if this is the right kind of question for SO, apologies if not, but I don’t know a better place. Much has already been said in other questions here, for example Is Java "pass-by-reference" or "pass-by-value"? and pass by reference or pass by value?, but I haven’t found an authoritative answer to the question what the term means.

I have thought that “pass by reference” means “pass a reference (usually a pointer) to the object”, so the callee can modify the object the caller sees, while “pass by value” means copying the object, and letting the callee have fun with the copy (obvious problem: what if the object contains references, deep copy or shallow).
Sing the FW turns up lots of places saying “pass by reference” means just that, here there’s some argument that it means more, but the definition still reads

A ParameterPassing mode where a reference (or if you want to be politically incorrect, a pointer) to the actual parameter is passed into the formal parameter; when the callee needs the formal parameter it dereferences the pointer to get it.

I haven’t found many places giving a stronger definition for the term, on this page, I found “The lvalue of the formal parameter is set to the lvalue of the actual parameter.” and, if I understand correctly, the same definition is used here (“The formal parameter merely acts as an alias for the actual parameter.”)

In fact, the only places I found where the stronger definition is used are places arguing against the notion that in Java, objects are passed by reference (that may be due to my lacking google-fu).

So, if I got things straight, pass-by-reference

class Thing { ... }
void byReference(Thing object){ ... }
Thing something;
byReference(something);

according to the first definition would roughly correspond to (in C)

struct RawThing { ... };
typedef RawThing *Thing;
void byReference(Thing object){
    // do something
}
// ...
struct RawThing whatever = blah();
Thing something = &whatever;
byReference(something); // pass whatever by reference
// we can change the value of what something (the reference to whatever) points to, but not
// where something points to

and in that sense, saying that Java passes objects by reference would be adequate. But according to the second definition, pass-by-reference means more or less

struct RawThing { ... };
typedef RawThing *RawThingPtr;
typedef RawThingPtr *Thing;
void byReference(Thing object){
    // do something
}
// ...
RawThing whatever = blah();
RawThingPtr thing_pointer = &whatever;
byReference(&thing_pointer); // pass whatever by reference
// now we can not only change the pointed-to (referred) value,
// but also where thing_pointer points to

And since Java only lets you have pointers-to-objects (limiting what you can do with them) but doesn’t have pointers-to-pointers, in that sense, saying that Java passes objects by reference is totally wrong.

So,

  1. Have I adequately understood the above definitions of pass-by-reference?
  2. Are there other definitions around?
  3. Is there consensus which definition is “the correct one”, if so, which?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:26:34+00:00Added an answer on May 26, 2026 at 11:26 pm

    Sure, different people currently have different definitions of what “pass-by-reference” means. And that is why they disagree on whether something is pass-by-reference or not.

    However, whatever definition you use, you must use it consistently across languages. You can’t say that one language has pass-by-value, and have the exact same semantics in another language and say that it is pass-by-reference. Pointing out the analogies between languages is the best way to address this dispute, because although people might have strong opinions about the passing modes in particular languages, when you contrast the identical semantics with other languages, it sometimes brings counter-intuitive results that force them to re-think their definition.

    • One predominant view is that Java is pass-by-value only. (Search everywhere on the Internet and you will find this point of view.) This view is that objects are not values, but are always manipulated through references, and thus it is references that are assigned or passed, by value. This view holds that the test of pass-by-reference is whether it is possible to assign to a variable in the calling scope.

    If one agrees with this viewpoint, then one must also consider most languages, including as diverse ones as Python, Ruby, OCaml, Scheme, Smalltalk, SML, Go, JavaScript, Objective-C, etc. as pass-by-value only. If any of this strikes you as strange or counterintuitive, I challenge you to point out why you think it is different between the semantics of objects in any of those languages from objects in Java. (I know that the some of these languages may explicitly claim that they are pass-by-reference; but it is irrelevant what they say; a consistent definition must be applied to all languages based on the actual behavior.)

    • If you take the opposing view that objects in Java are pass-by-reference, then you must also consider C as pass-by-reference.

    Take your Java example:

    class Thing { int x; }
    void func(Thing object){ object.x = 42; object = null; }
    Thing something = null;
    something = new Thing();
    func(something);
    

    in C, it would be equivalent to this:

    typedef struct { int x; } Thing;
    void func(Thing *object){ object->x = 42; object = NULL; }
    Thing *something = NULL;
    something = malloc(sizeof Thing);
    memset(something, 0, sizeof(something));
    func(something);
    // later:
    free(something);
    

    I claim that the above are semantically equivalent; only the syntax is different. The only syntax differences are:

    1. C requires an explicit * to denote a pointer type; Java’s reference (pointers to objects) types don’t need an explicit *.
    2. C uses -> to access a field through a pointer; Java just uses .
    3. Java uses new to dynamically allocate memory for a new object on the heap; C uses malloc to allocate it, and then we need to initialize the memory.
    4. Java has garbage collection

    Note that, importantly,

    1. The syntax for calling the function with the object are the same in both cases: func(something), without needing to do anything like taking address or anything.
    2. In both cases, the object is dynamically-allocated (it may live beyond the scope of the function). And
    3. In both cases, the object = null; inside the function does not affect the calling scope.

    So the semantics are the same in both cases, so if you call Java pass-by-reference you must call C pass-by-reference too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A question for anyone who has used the Java library Mallet's SimpleTagger class for
Is there anyone who has succeeded in making a self-contained .war file using Tomcat
Who has the most readable and useful function/class commenting convention? I'm not looking for
I have a client who has brought in another developer to work on a
I have an NSManagedObject who has a one to many relationship with the parent
Is there anyone who has already tried to use the Microsoft Bing translator web
I have a client who has one webpage with customized routes added in global.asax
I have a client who has built her entire site using html extensions. As
I got a app who has Sonata User bundle and Sonata Admin bundle ,
I am a programmer who has programmed in several languages, both functional and OO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.