import java.util.*;
public class Elway {
public static void main(String r[]) {
ArrayList[] ls = new ArrayList[3];
for(int i=0; i<3; i++) {
ls[i] = new ArrayList();
ls[i].add("a" + i); }
Object o = ls;
do3(ls);
for(int i=0; i<3; i++)
//insert code here
}
static Object do3(ArrayList[] a) {
for(int i=0; i<3; i++) a[i].add("e");
return a;
}
}
The code above compiles fine with:
a. System.out.println(((Object[])o)[i] + " ")
b. System.out.println(((ArrayList[])o)[i] + " ")
but not with
c. System.out.println(o[i] + " ")
What is the reason? When we assigned ls to o, didn't Object o become an array?