Reputation: 4673
This:
Timerange longest = Timerange.longest(breaks);
if (longest.durationInHours() >= MIN_FREE_HOURS)
return true;
is OK.
But this:
if (Timerange.longest(breaks).durationInHours() >= MIN_FREE_HOURS)
return true;
gives:
java.lang.ClassCastException
Do you know why?!
For simplicity:
public static final <T extends Timerange> T longest(List<T> timeranges) {
return timeranges.get(0);
}
Breaks:
List<Duty> breaks = week.substract(weekDuties);
Upvotes: 1
Views: 345
Reputation: 147164
Presumably somewhere in your code you are getting a warning. Listen to your compiler.
To get details add -Xlint
(in particular -Xlint:unchecked
) to your javac commandline (or do your development environment's equivalent).
Upvotes: 0
Reputation: 21950
What happens if you try:
if (((Timerange) Timerange.longest(breaks)).durationInHours() >= MIN_FREE_HOURS)
return true;
e.g., cast it?
Upvotes: 1