Look at the code
public class Sample {
public static void main(String[] args) {
Cache.load();
System.out.println(Cache.get());
}
}
class Cache {
static List<String> l = new ArrayList<String>();
public static List<String> get() {
return l;
}
public static void load() {
l.add("shiva");
l.add("rachakonda");
}
}
When Cache.load() is called array list object is initialized and after calling Cache.get(), it is able to give list elements. How the arrayList data is still available? I've expected the output as empty list.