mirror of
https://github.com/sjsdfg/effective-java-3rd-chinese.git
synced 2025-02-06 09:40:10 +08:00
Update 30. 优先使用泛型方法.md
This commit is contained in:
parent
e553edf61a
commit
3a5a953b7d
@ -114,18 +114,13 @@ public static <E extends Comparable<E>> E max(Collection<E> c);
|
||||
```java
|
||||
// Returns max value in a collection - uses recursive type bound
|
||||
public static <E extends Comparable<E>> E max(Collection<E> c) {
|
||||
|
||||
if (c.isEmpty())
|
||||
throw new IllegalArgumentException("Empty collection");
|
||||
|
||||
E result = null;
|
||||
|
||||
for (E e : c)
|
||||
if (result == null || [e.compareTo(result](http://e.compareTo(result)) > 0)
|
||||
result = Objects.requireNonNull(e);
|
||||
|
||||
return result;
|
||||
|
||||
if (c.isEmpty())
|
||||
throw new IllegalArgumentException("Empty collection");
|
||||
E result = null;
|
||||
for (E e : c)
|
||||
if (result == null || e.compareTo(result) > 0)
|
||||
result = Objects.requireNonNull(e);
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user