这是一个非常简短直接的问题,但我一直无法找到答案.考虑以下情况.
ArrayList<A> listOne, listTwo;
listOne = new ArrayList<A>();
listTwo = listOne;
Run Code Online (Sandbox Code Playgroud)
我的问题是发生了什么listTwo.从C"nativespeaker"的角度来看,只复制指针而不执行其他操作,或者列表是否复制到新的内存区域中.我对此代码的目标如下:
ArrayList<A> listOne, listTwo, auxList;
//listOne and listTwo have been initialized and filled somewhere else.
public void method( int opType ){
if( opType == 0)
auxList = listOne; //Set pointer, not copy list;
else
auxList = listTwo; //Set pointer, not copy list;
....
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |