Campbell Ritchie wrote:Good grief! Have you got separate keys and data arrays? I don't like parallel arrays; I think it is a very error‑prone approach. Create pair objects (or better still, Map.Entry<K, V> objects).
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions | How to Answer Questions | Format Your Code
Mj Lewis wrote:
QUESTION: The element in data[index] is an object that answer now refers to. However, we the change that object to be a null reference. So, why doesn't answer now reference the null object? Shouldn't this follow the whole "pass by value / pass by reference" logic whereby any changes to the underlying object should impact everything that references it?
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions | How to Answer Questions | Format Your Code
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions | How to Answer Questions | Format Your Code
Mj Lewis wrote:Shouldn't this follow the whole "pass by value / pass by reference" logic whereby any changes to the underlying object should impact everything that references it?
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions | How to Answer Questions | Format Your Code
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions | How to Answer Questions | Format Your Code
Junilu Lacar wrote:
Mj Lewis wrote:Shouldn't this follow the whole "pass by value / pass by reference" logic whereby any changes to the underlying object should impact everything that references it?
The behavior has nothing to do with pass by value or by reference. By the way, in Java everything is passed by value. It's incorrect to think that anything is passed by reference. Even reference variables are passed by value. It's critical that you understand that concept otherwise you'll confuse yourself, just as in this case.
Junilu Lacar wrote:
Mj Lewis wrote:
QUESTION: The element in data[index] is an object that answer now refers to. However, we the change that object to be a null reference. So, why doesn't answer now reference the null object? Shouldn't this follow the whole "pass by value / pass by reference" logic whereby any changes to the underlying object should impact everything that references it?
What you seem to think should happen:
1. data[index] --> (E)
2. answer --> data[index] --> (E)
3. answer --> data[index] --> null
What is actually happening:
1. data[index] --> (E)
2. data[index] --> (E) <-- answer
3. data[index] --> null
(E) <-- answer
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
How to Ask Questions | How to Answer Questions | Format Your Code
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
|