I am instatiating an object outside For and changing value like this:
NotaCaract dadosNota = aux.getListaNotasInicial().createNewNotaCaract();
for(int i=0; i< saida.getListaCompletaProds().size(); i++){
seqIdNota = saida.getListaCompletaProds().getDadosCompletosProd(i).getIdNota().getIntValue();
dadosNota.getIdNota().setIntValue(seqIdNota);
aux.getListaNotasInicial().addNotaCaract(dadosNota);
seqNotaDesFornecedor = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqNotaDesFornecedor().getIntValue();
dadosNota.getIdNota().setIntValue(seqNotaDesFornecedor);
aux.getListaNotasInicial().addNotaCaract(dadosNota);
seqNotaDesMorada = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqMorada().getIntValue();
dadosNota.getIdNota().setIntValue(seqNotaDesMorada);
aux.getListaNotasInicial().addNotaCaract(dadosNota);
seqNotaMoradaFornecedor = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqNotaMoradaFornecedor().getIntValue();
dadosNota.getIdNota().setIntValue(seqNotaMoradaFornecedor);
aux.getListaNotasInicial().addNotaCaract(dadosNota);
seqFinalidadeFinanciamento = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqFinalidadeFinanciamento().getIntValue();
dadosNota.getIdNota().setIntValue(seqFinalidadeFinanciamento);
aux.getListaNotasInicial().addNotaCaract(dadosNota);
seqJustificacao = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqJustificacao().getIntValue();
dadosNota.getIdNota().setIntValue(seqJustificacao);
aux.getListaNotasInicial().addNotaCaract(dadosNota);
seqObservacaoAmbitoProposta = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqObservacaoAmbitoProposta().getIntValue();
dadosNota.getIdNota().setIntValue(seqObservacaoAmbitoProposta);
aux.getListaNotasInicial().addNotaCaract(dadosNota);
}
Let's suppose only first instance has a value 1 and all other values are 0. My final List aux.getListaNotasInicial() will be all 0's.
But when i do this:
for(int i=0; i< saida.getListaCompletaProds().size(); i++){
NotaCaract dadosNota = aux.getListaNotasInicial().createNewNotaCaract();
seqIdNota = saida.getListaCompletaProds().getDadosCompletosProd(i).getIdNota().getIntValue();
dadosNota.getIdNota().setIntValue(seqIdNota);
aux.getListaNotasInicial().addNotaCaract(dadosNota);
NotaCaract dadosNotaDesFornecedor = aux.getListaNotasInicial().createNewNotaCaract();
seqNotaDesFornecedor = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqNotaDesFornecedor().getIntValue();
dadosNotaDesFornecedor.getIdNota().setIntValue(seqNotaDesFornecedor);
aux.getListaNotasInicial().addNotaCaract(dadosNotaDesFornecedor);
NotaCaract dadosNotaDesMorada = aux.getListaNotasInicial().createNewNotaCaract();
seqNotaDesMorada = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqMorada().getIntValue();
dadosNotaDesMorada.getIdNota().setIntValue(seqNotaDesMorada);
aux.getListaNotasInicial().addNotaCaract(dadosNotaDesMorada);
NotaCaract dadosNotaMoradaFornecedor = aux.getListaNotasInicial().createNewNotaCaract();
seqNotaMoradaFornecedor = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqNotaMoradaFornecedor().getIntValue();
dadosNotaMoradaFornecedor.getIdNota().setIntValue(seqNotaMoradaFornecedor);
aux.getListaNotasInicial().addNotaCaract(dadosNotaMoradaFornecedor);
NotaCaract dadosNotaFinalidadeFinanciamento = aux.getListaNotasInicial().createNewNotaCaract();
seqFinalidadeFinanciamento = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqFinalidadeFinanciamento().getIntValue();
dadosNotaFinalidadeFinanciamento.getIdNota().setIntValue(seqFinalidadeFinanciamento);
aux.getListaNotasInicial().addNotaCaract(dadosNotaFinalidadeFinanciamento);
NotaCaract dadosNotaJustificacao = aux.getListaNotasInicial().createNewNotaCaract();
seqJustificacao = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqJustificacao().getIntValue();
dadosNotaJustificacao.getIdNota().setIntValue(seqJustificacao);
aux.getListaNotasInicial().addNotaCaract(dadosNotaJustificacao);
NotaCaract dadosNotaObservacaoAmbitoProposta = aux.getListaNotasInicial().createNewNotaCaract();
seqObservacaoAmbitoProposta = saida.getListaCompletaProds().getDadosCompletosProd(i).getProdutosLeasing().getSeqObservacaoAmbitoProposta().getIntValue();
dadosNotaObservacaoAmbitoProposta.getIdNota().setIntValue(seqObservacaoAmbitoProposta);
aux.getListaNotasInicial().addNotaCaract(dadosNotaObservacaoAmbitoProposta);
}
My final list aux.getListaNotasInicial() will have exactly the values i want it to have. Why do i have to instatiate multiple objects inside loop to use their values, when i could just instatiate only 1 and change his value as i wish?
PS: My platform only supports Java 6 Ty