I wrote the following code in Eclipse, I think all lines should print
true
true
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.WEEK_OF_YEAR, -1);
System.out.println(cal.before(date));
System.out.println(cal.getTime().before(date));
This is the code of the function Calendar.before(Object when)
:
public boolean before(Object when) {
return when instanceof Calendar
&& compareTo((Calendar)when) < 0;
}
As you can see, it checks if given object is Calendar
, and if it is not, like in your case, it returns false
.