I have a class like this:
public class DateS extends Date {
public DateS yesterday(){
Calendar cal = Calendar.getInstance();
cal.setTime(this);
cal.add(Calendar.DAY_OF_YEAR, -1);
return (DateS) cal.getTime();
}
}
It can be successfully built. At runtime, when I call date.yesterday()
, a Cannot cast 'java.util.Date' to 'myproject.package.DateS'
are throwed.
I need to know why and what can I do to fix this.