mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
feat: new object with 'of' method
This commit is contained in:
@@ -474,4 +474,19 @@ public class ListUtil {
|
||||
public static <T> List<T> empty() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 像java11一样获取一个List
|
||||
* @param ts 对象
|
||||
* @param <T> 对象类型
|
||||
* @return 不可修改List
|
||||
*/
|
||||
public static <T> List<T> of(T... ts) {
|
||||
if (ArrayUtil.isEmpty(ts)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<T> unmodifiableList = new ArrayList<>(ts.length);
|
||||
Collections.addAll(unmodifiableList, ts);
|
||||
return Collections.unmodifiableList(unmodifiableList);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user