How about Collections.emptySorted[Set|Map] ?
assembling signals
assembling.signals at yandex.ru
Sat Apr 17 17:46:16 UTC 2010
This is a nice idea!
Additionally, (inspired by this idea,) emptyList() could return something that is castable to Deque
(which is a sub-interface of Queue). Think of an empty plus unmodifiable LinkedList (which implements List, Deque, Queue).
Deque<String> d = (Deque<String>) Collections.emptyList();
This, together with the Sorted[Set|Map] proposal, would cover most important collections interfaces, right?
17.04.10, 14:03, "Osvaldo Doederlein" <opinali at gmail.com>:
> 2010/4/17 assembling signals <assembling.signals at yandex.ru>
> > Hello, everyone!
> >
> > In the Collections utility class we have
> >
> > * emptyMap()
> > * emptySet()
> >
> > * unmodifiableSet(...)
> > * unmodifiableMap(...)
> > * unmodifiableSortedSet(...)
> > * unmodifiableSortedMap(...)
> >
> > So we have no
> >
> > * emptySortedMap()
> > * emptySortedSet()
> >
> > I have several times encountered situations where methods needed either SortedSet or SortedMap.
> >
> > Do you think in would be appropriate to introduce the two proposed methods?
> >
>
> Why not just changing the implementation of the existing emptyMap() and emptySet(), so they return an object that is additionally sorted? This would require a typecast, e.g. SortedMap map = (SortedMap)Collections.emptyMap(); but wouldn't require changing the existing API, or adding any new API. Just make very clear in the documentation that the typecast is valid only @since 1.7.
>
> A+
> Osvaldo
More information about the core-libs-dev
mailing list