Showing posts with label java. Show all posts
Showing posts with label java. Show all posts
The following lines of code did not work as I expected:
Date monthStartDate = null;
Date monthEndDate = null;
dateTimeUtil.fillStartAndEndDate(date, monthStartDate, monthEndDate);
getLog().info("START: " + monthStartDate);
getLog().info("END: " + monthEndDate);
And the fillStartAndEndDate method:
public void fillStartAndEndDate(Date date, Date start, Date end) {
DateTime dateTime = new DateTime(date.getTime());
int startDay = dateTime.dayOfMonth().getMinimumValue();
DateTime startDate = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), startDay, 0 ,0 ,0 ,0);
int endDay = dateTime.dayOfMonth().getMaximumValue();
DateTime endDate = new DateTime(dateTime.getYear(), dateTime.getMonthOfYear(), endDay, 0 ,0 ,0 ,0);
start = jodaDateTimeToJavaDate(startDate);
end = jodaDateTimeToJavaDate(endDate);
}
The results were the following:
START: null
END: null
This is one of those very basic things I sometimes overlook. At first, I thought that object reference in java works the same as the object reference in c++. In java, after creating a new instance of the object, the object (start param variable on the example) is not anymore pointing to the same reference which makes the method's local variable have a different value from the one that was originally passed.
Subscribe to:
Posts (Atom)