Java Reference
In-Depth Information
int[] array {1,2,3}
.......
Memory Address
#000023
figure 4-4  
Next, you call the following method:
Test.increaseFirstInt(t.array);
t.array is also a non‐primitive type, so once again, try to imagine this variable as a piece of paper
holding an address. When you write t.array , think of Java first going to the address in memory
written on the piece of paper for t , then retrieving the array variable there, which contains another
address pointing toward the location in memory where the actual data can be found. When you
write t.array[0] , you would thus traverse two memory addresses to eventually find the actual inte-
ger data. Figure 4-5 shows a simplified view of the basic idea.
Memory Address
#000023
Memory Address
#000025
Test t
int[] t.array
t.array[0]
23
24
25
26
27
t object
(general info, such
as length of
following variable
addresses)
array var
=
000025
array[0]
= 1
array[1]
= 2
array[2]
= 3
figure 4-5  
The address written on the t.array piece of paper is passed to the increaseFirstInt method by value
(!). This means that you do not pass the piece of paper itself, but instead take another sheet of paper,
write down the same address, and use that piece within the method (a copy of the address is made).
Search WWH ::




Custom Search