generics - Why Java PriorityQueue<T> does not enforce a Comparable Object -
why priorityqueue in java defined as,
priorityqueue<t>
and not as,
priorityqueue<t extends comparable<? super t>
it rather gives classcastexception @ runtime if not queue objects of type comparable. (and if not using custom comparator).
why not grab @ compile time?
it's done can still utilize priority queue objects not implement comparable
interface. in such cases supply own custom comparator , works.
this increases usability of class, @ minimal no cost. behavior well-documented in javadoc.
java generics collections priority-queue
No comments:
Post a Comment