mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-30 20:57:59 +08:00
feat: new object with 'of' method
This commit is contained in:
parent
018999e18f
commit
7588535cac
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user