You put T in, you get T out.
I'm open to suggestions as to whether this is the right thing. I think if it were returning a view, we'd definitely want it like this. You don't want a List<Integer> to look like a List<Number> and have it break something when someone stuffs a Float in it. But the argument could be made that returning a new List can surely be seen as a List<Number> because it is not referenced anywhere else as something more specific. Many of the guava methods allow a "re-typing" like this, although I think they have admitted that it was a mistake and newly added methods don't allow it. In any case, I think that it's most proper to retain things as specifically as possible. Why would you turn a List<Integer> into a List<Number>? Why would you want to throw away the information? If you need to pass it to a method that expects List<Number> then that method should be modified to correctly accept List<? extends Number>. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2958 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -135,7 +135,7 @@ public class CollectionUtil
|
||||
*
|
||||
* @throws NoSuchElementException if the Iterable is empty.
|
||||
*/
|
||||
public static <T extends Comparable<? super T>> List<T> maxList (Iterable<? extends T> iterable)
|
||||
public static <T extends Comparable<? super T>> List<T> maxList (Iterable<T> iterable)
|
||||
{
|
||||
return maxList(iterable, new Comparator<T>() {
|
||||
public int compare (T o1, T o2) {
|
||||
@@ -150,9 +150,9 @@ public class CollectionUtil
|
||||
*
|
||||
* @throws NoSuchElementException if the Iterable is empty.
|
||||
*/
|
||||
public static <T> List<T> maxList (Iterable<? extends T> iterable, Comparator<? super T> comp)
|
||||
public static <T> List<T> maxList (Iterable<T> iterable, Comparator<? super T> comp)
|
||||
{
|
||||
Iterator<? extends T> itr = iterable.iterator();
|
||||
Iterator<T> itr = iterable.iterator();
|
||||
T max = itr.next();
|
||||
List<T> maxes = new ArrayList<T>();
|
||||
maxes.add(max);
|
||||
@@ -186,7 +186,7 @@ public class CollectionUtil
|
||||
*
|
||||
* @throws NoSuchElementException if the Iterable is empty.
|
||||
*/
|
||||
public static <T extends Comparable<? super T>> List<T> minList (Iterable<? extends T> iterable)
|
||||
public static <T extends Comparable<? super T>> List<T> minList (Iterable<T> iterable)
|
||||
{
|
||||
return maxList(iterable, java.util.Collections.reverseOrder());
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class CollectionUtil
|
||||
*
|
||||
* @throws NoSuchElementException if the Iterable is empty.
|
||||
*/
|
||||
public static <T> List<T> minList (Iterable<? extends T> iterable, Comparator<? super T> comp)
|
||||
public static <T> List<T> minList (Iterable<T> iterable, Comparator<? super T> comp)
|
||||
{
|
||||
return maxList(iterable, java.util.Collections.reverseOrder(comp));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user