I have a question to draw the memory model diagram for the code below:
With the given answer here:
My question is why is the value for next stored inside the box while the values for data (11 and 5) are pointed to outside the box. I am thinking it is because it is a null value, but what is the reason if so?
11 are primitive values. Since
data is a reference type to
data cannot be a primitive type, so it is a reference (hmm, I already said that) to the object (e.g.
Integer) holding the primitive value (e.g.
Reference types like
Node (bad, bad code, using a raw generic), can either reference an object, or be
null is that actual value of the type.
data can reference an object of type
E, or be
null if your list allow null values.