Collections subtle differences in Java -
why have mention capacity in case of priorityqueue
constructor when using comparator priorityqueue
, not case other collections use comparator , sort of capacity in constructor not mandatory , compiles fine while in case of priorityqueue
if have use comparator have mention capacity else compile time error thrown.
class pq { priorityqueue<integer> pq2 = new priorityqueue<integer>(10, new pq.pqsort()); static class pqsort implements comparator<integer> { public int compare(integer one, integer two) { return two.compareto(one); } } }
you'd need ask api designers.
i guess did not want provide overloaded constructors possible combinations of optional arguments. ones think used, , 1 options (where have provide defaults ones don't care about).
other languages solve having optional, named parameters defaults. in java, stuck positional parameters (and api designers choosing provide many convenient overrides see fit).
Comments
Post a Comment