Please help me on this problem

public class DBAdapter {
(...)
     private Calendar calendar;

     public DBAdapter(
               Context context,
               String harborCode,
               Calendar calendar)
        {
                        this.calendar = calendar;
                        (...)
        }
     public Calendar     getCalendar()     { return this.calendar; }
     public int     getDate()     { return this.calendar.get(Calendar.DATE); }

(...)

     private void replaceMonthOnline() throws IOException {
          /*
           * WHY DOES IT CHANGE THIS.CALENDAR ?!?
           */
          
          Calendar tmpCalendar = getCalendar();
          int monthMax = tmpCalendar.getActualMaximum(Calendar.DATE);
          int monthMin = tmpCalendar.getActualMinimum(Calendar.DATE);

          tmpCalendar.set(Calendar.DATE, monthMin); // <---- THE PROBLEM IS EVIDENT FROM HERE ON.
(...)
And it changes the date also in this.calendar.

I want tmpCalendar to be changed without changing the Calendar class, too. How can I do this?

I think it has something to do with the design of PBR. But how to achieve what I want in this case, another calendar with the same values, and that a change will not change the other?

Thank you.

Published by: 801999 on October 12, 2010 20:29

Published by: 801999 on October 12, 2010 20:29

If you want another calendar object, then create a. What you have there is just an object of calendar with several references, all to this single object.

Calendar anotherCalendarObject = Calendar.getInstance();
anotherCalendarObject.setTime(theFirstCalendarObject.getTime());

Tags: Java

Similar Questions

Maybe you are looking for