mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复CollUtil.reverseNew针对非可变列表异常
This commit is contained in:
@@ -371,7 +371,13 @@ public class ListUtil {
|
||||
// 不支持clone
|
||||
list2 = new ArrayList<>(list);
|
||||
}
|
||||
return reverse(list2);
|
||||
|
||||
try {
|
||||
return reverse(list2);
|
||||
} catch (final UnsupportedOperationException e) {
|
||||
// 提供的列表不可编辑,新建列表
|
||||
return reverse(list(false, list));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -254,4 +254,11 @@ public class ListUtilTest {
|
||||
ListUtil.setOrPadding(list, 3, "a");
|
||||
Assert.assertEquals(4, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reverseNewTest() {
|
||||
final List<Integer> view = ListUtil.of(1, 2, 3);
|
||||
final List<Integer> reverse = ListUtil.reverseNew(view);
|
||||
Assert.assertEquals("[3, 2, 1]", reverse.toString());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user