Search code examples
javacomparisonoperatorsoperator-overloadinggregorian-calendar

Is there a way to add methods to GregorianCalendar in Java?


I'd like to make a method called "isBetween" returning a boolean, seeing if a GregorianCalendar date falls between two others. Alternatively, I'd like to just define operators of < and > for the class. I'm pretty new to Java, so I'm not sure....can I even do either of those? If so, how?


Solution

  • Java does not support monkeypatching or operator overloading, but feel free to subclass GregorianCalendar and add whatever methods you need.

    But then, do you really need a new method to do cal.after(startCal) && cal.before(endCal) ?