Re: pass by reference



Andreas Leitgeb wrote:
a) Does anyone disagree, that "pass an Object by reference" and "pass
the reference to an Object by value" refer to the same technical
feature?

Yes, we basically all disagree. This is based on the simple fact that
they are different things. You can't do one of them in Java, whereas you
can do the other.

In C++, a language where you can do both, the difference is in whether
you specify the parameter as `Class &v` or `Class *v`. The first passes
an object by reference, while the second passes a pointer (basically a
reference in Java terminology) by value.

b) Does anyone disagree that "pass a reference by reference" is an
entirely different feature that is not directly supported by java, but
can be effectively mimicked with arrays and/or Holder- classes?

This is a special case of the fact that "pass X by reference" is always
not directly provided by Java, for all values of X. You've plugged "a
reference" for X there, so you have a true statement. It would remain
true no matter what else you substitute for X.

Would anyone care to point out any difference of the two concepts in
"a)" without mixing it up with the concept in "b)" ?

I've been trying. If you don't see what I'm saying, feel free to ask,
but please point out what you disagree with or don't understand.

In C#, you can additionally pass parameters by reference, including
references.

This is also "pass ... by reference", but with C#'s meaning of
references, whereas Java's "pass Objects by reference" is based on
java's "references". Therefore "pass by reference" means something
different depending on the language context.

Actually, this may be the point of confusion. Pass by reference is a
concept that has a particular meaning, independent of any other use of
the word "reference" in a language. In particular, pass by reference has
nothing to do with references in Java, or C#, or Ocaml, or most other
languages that call something a reference. The two concepts are related
in C++ specifically because the language committee chose to define
references as a generalization of the concept of pass by reference; i.e.,
a reference in C++ is simply another symbol, with a possibly different
scope, that denotes the same object as the symbol it is initialized from.

--
Chris Smith
.



Relevant Pages

  • Re: The Java no pointer big fat lie!
    ... > reference types, it wouldn't be a good comparison. ... and what you can't - and there is a big difference in Java to C and C++. ... You cannot change it in the language itself, ... Thus I would distinguish pointers from ...
    (comp.lang.java.programmer)
  • Re: Why C# and Java have got it wrong
    ... there are GC languages other than Java. ... > you used any language which conveniently supports higher order functions ... and I must apologize: garbage collection is ... > a reference to the proxy object living on the stack. ...
    (comp.programming)
  • Re: Question on LSP
    ... not have to be explicit attributes, ... Since objects in memory usually don't move, the language can largely hide the identity mapping. ... My issue here is that whatever semantic meta model the language uses, there must be some way for the developer to unambiguously express the OOA/D is-a semantics for some problem space entity. ... Note that the language allows us to use a name like 'T' on the reference as a mnemonic so that the developer can keep track of what is happening with the indirection. ...
    (comp.object)
  • Re: call by reference
    ... but if saying "Java has call by reference" makes ... >user of the language shouldn't really need to know how the language is ... but I know that many things about Java made more ... perfect sense. ...
    (comp.lang.java.programmer)
  • Re: pass by reference
    ... talking about Java, that it does when talking about other languages. ... this is also true for "reference" itself. ... Because one "reference" is an object reference, ... This is natural language as I understand it. ...
    (comp.lang.java.programmer)