Krep Lock wrote:
Are there any subtle differences between the following?
The key to understanding this is to remember that every array is an Object; i.e., you can say
Object intArray = new int[] { 1, 2, 3 };
and similarly, you can also say
Object stringArray = new String[] { "a", "b", "c" };
in both cases, you can't treat the arrays as arrays without casting them. So in the second case, you can say
String[] usableStringArray = (String[]) stringArray;
and then access the Strings in the array. But also note that for every reference type X that is a subtype of Y, X[] is a subclass of Y[] -- i.e., String[] is a subclass of Object[], so an Object[] variable can refer to a String[], and you can access the members of the array that way:
Object[] semiUsableStringArray = (Object[]) stringArray;
So although those original two lines of code look similar, they're rather different in meaning and intent.