Hello, I've been messing with the GregorianCalendar class and I came across the following problem:
You had to go from one point in the calendar to the other, then set the first point as the second, then "reset" the second field and go back. basically the following:
GregorianCalendar gc1=new GregorianCalendar();
GregorianCalendar gc2=new GregorianCalendar();
gc1.setTime(meuTempo1);
gc2.setTime(meuTempo2);
while(!gc2.equals(variavel)){//eu tinha que voltar a gc2 até um determinado ponto
//que não necessariamente é igual a gc1.
//percorre o tempo, tirando o tanto de gc2
}
gc1=gc2;//aqui está o problema
gc2.setTime(meuTempo2);
Basically, I ran back a certain, gave a gc1=gc2
and set the gc2 again as it was before. The problem is that when I gave gc2.setTime(meuTempo2);
the variable gc1 also received that parameter, that is, the attributes of gc1 also changed, as if I had placed a second line gc1.setTime(meuTempo2);
.
It was easy to solve this, just replace gc1=gc2
with gc1.setTime(gc2.getTime());
but I was in doubt, if I instantiated a new variable, should not it take the attributes and then be independent of the second? If not, in what cases can this happen? And if possible, how to deal with this problem?