posted 24 years ago
int[] arr = {1, 2, 3, 4, 5};
somefunc(arr); // call somefunc passing array
System.out.println(arr[1]); // prints second integer
'arr' is a reference to an array of 5 integers. Any place you can use 'arr' in your code, you could use an anonymous class (remember an array IS an object.)
somefunc(new int[] {1, 2, 3, 4, 5}); // same thing
// can't get to array, no reference!
The big difference is I don't have a reference to the anonymous array to use anywhere else, other than to where it was passed (somefunc()).