10
Karlson
2y

Java and C were telling jokes. It was C's turn, so he writes something on the wall, points to it and says "Do you get the reference?" But Java didn't.

Comments
  • 1
    I don't get it...
    Java gets everything by ref. Always. Except for the primitives - they are by-value.
  • 1
    @netikras not quite. If that were the case, reassigning an argument would reassign the original thing too
  • 0
    No one didnt, it was a nulll pointer reference haha
  • 2
    @ess3sq arguments are copies of references stored in stack. Quite a different mechanism, different memory pools.If we dive deep into jvm internals, we could discuss endlessly. As far as java code is concerned, my first message holds true
  • 1
    @netikras you are not wrong, although I wouldn't call them references, more like constant pointers copied on the stack. (If we are comparing the semantics to C++ constructs). Might be that the wrong wording is being used.

    Edit: it's still pass by value though, we are simply passing references/pointers/whatever by value
  • 0
    @ess3sq reference is a value by itself :)

    it's like unittests. Unit can be a loc, unit can be a function, unit can be a service. It depends on what level you call a unit.
    Same thing about references/pointers. They all are a value [a numeric address] at the bottom level. But it's a virtually valueless concept [just an indirect accessor of a value] if we're talking about a flyweight design pattern.

    Same thing can be seen very differently. Depends on a context
  • 0
    @ess3sq no, Java object parameters are not passed by value. Even though you are right that the reference itself is passed by value, the term "passed by reference" is exactly what is used to describe that the reference is copied.
Add Comment