Java Object and array memory location

拈花ヽ惹草 提交于 2019-12-04 20:00:05

The array will be an object on the heap containing pointers to the Pair objects which will also be on the heap (but separate from the array itself).

No, the storage array will only contain pointers to the actual Pair objects existing somewhere else on the heap. Yet, remember to instantiate 8 Pair objects and make each element of the array point to these objects. You need to have something like this after the code that you have written:

for(int i=0;i<storage.length;i++)
    storage[i] = new Pair() ;

Only then will the Pair objects be created and correctly referred to by the storage array.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!