Why does this code compile and run successfully it seems that it should get an index out of bounds

advertisements

I was reading through some java code in a project I was working on and came along a method with something to this effect in it.

Object[] objs = null;
objs[0] = str1;
objs[1] = obj1;
for(String str: strArray)
{
    objs[objs.length+1] = str;
}

I can't figure out what is going on here. I was hoping someone could explain how this code is working to me, preferably on both a high level and the behind the scenes low level.


That should not run. objs[0] will give an error.

Are you sure you are running the correct version of the file?