public final class InstanceUtils extends Object
ClassUtils,
InstantiationException| 限定符和类型 | 方法和说明 |
|---|---|
static <T> Optional<T> |
newInstance(Class<T> type)
尝试创建实例
|
static <T> Optional<T> |
newInstance(String className)
尝试加载类型并创建实例
|
static <T> T |
newInstanceOrThrow(Class<T> type)
创建实例,不成功时抛出默认异常
|
static <T> T |
newInstanceOrThrow(Class<T> type,
Supplier<? extends RuntimeException> exceptionIfCannotCreateInstance)
创建实例,不成功时抛出异常
|
public static <T> T newInstanceOrThrow(Class<T> type)
T - 实例类型泛型type - 类型InstantiationException - 创建实例无法成功public static <T> T newInstanceOrThrow(Class<T> type, Supplier<? extends RuntimeException> exceptionIfCannotCreateInstance)
T - 实例类型泛型type - 类型exceptionIfCannotCreateInstance - 异常提供器public static <T> Optional<T> newInstance(Class<T> type)
T - 实例类型泛型type - 类型Copyright © 2022. All rights reserved.