어떤 것이 더 효율적이고 빠르며 그 이유는 무엇입니까? 배열의 객체에 직접 액세스하거나 temp 객체를 생성 하시겠습니까? 안드로이드 시스템의 경우2 차원 배열의 객체에 액세스
는 내가 직접 액세스가 낫다는 것을 들었다, 빠르고 덜 가비지 컬렉션
public static Foo [10][10];
public class Foo{
int score;
int age;
int type;
}
옵션 1 :
for(int col = 0; col < 10; col++)
for(int row = 0; row < 10; row++){
int temp = Foo[col][row].score;
int temp_two = Foo[col][row].age;
int temp_three = Foo[col][row].type;
}
옵션 2 :
for(int col = 0; col < 10; col++)
for(int row = 0; row < 10; row++){
Foo tempFoo = Foo[col][row];
int temp = tempFoo.score;
int temp_two = tempFoo.age;
int temp_three = tempFoo.type;
}
감사합니다
안녕하세요 크리스, 내가 임시 foo에 액세스 변수 중 하나가 그 변화의 원인이됩니다 변경하는 경우 배열에 저장된 원래 foo에? (foo.score = 5) –
예, temp foo는 원래 foo에 대한 참조이므로. 복사본이 아닙니다. – trooper