In the code below, I would like the second method to be generic, too, but since I create the Calendar object inside the method, because of type erasure, I don't see how. One possibility would be to pass in the Calendar object, but that would defeat the main purpose for having this method at all (not having to think about the Calendar objects).
How can I make the second method work for multiple subclasses of Calendar, like the first method does?
public static <U extends Calendar> CalendarMatch<U> tpFromCalendar(U dt)
{
// we want to do all comparisons on UTC calendars
dt.setTimeZone(TimeZone.getTimeZone(DEFAULT_TZ_ID));
return new CalendarMatch<U>(dt);
}
public static CalendarMatch<GregorianCalendar> tpDailyGregorian(int h)
{
GregorianCalendar dt = new GregorianCalendar(TimeZone.getTimeZone(DEFAULT_TZ_ID));
dt.clear();
dt.set(Calendar.HOUR, h);
// this works because of type inference
return tpFromCalendar(dt);
}