Working my way through the
Java 8 OCA Study guide by Boyarsky and Selikoff (exam 1Z0-808) and have a question regarding the text on page 119/120. The authors break down what the following declaration is:
char[] letters
where:
char is a primitive and what goes into the reference variable
letters is a reference variable
[] notation indicates an array
They give four samples on page 120 that are functionally equivalent (I have modified slightly to match the first example):
char[] letters;
char [] letters;
char letters[];
char letters [];
Until I read this text, I always believed that it was read as 'a reference variable named 'letters' that contains an array of char values' but I may have to modify this based on what I have read. It seems to indicate something slightly different like 'an array named 'letters' that contains char values'. I guess you could argue semantics but it seems different to me.
What concerned me more was the example on page 121 as follows:
The definition of:
int[] ids, types; // two reference variables that are arrays that contain int values)
is DIFFERENT than:
int ids[], types // one reference variable (ids) that is an array that contains int values and an int primitive named 'types'
At first I thought the second line would not compile as it was two different types you were trying to initialize on the same line but based on my 'new' interpretation, they are both int primitives and it is the reference variable that is different (one being an array and another being a regular int).