类 TypeUtils

java.lang.Object
io.agentscope.core.util.TypeUtils

public final class TypeUtils extends Object
Utility class for type-safe operations.
  • 方法详细资料

    • safeCast

      public static <T> T safeCast(Object obj, Class<T> clazz)
      Safely cast an object to the specified type.
      类型参数:
      T - The target type
      参数:
      obj - The object to cast
      clazz - The target class
      返回:
      The casted object
      抛出:
      ClassCastException - if the object is not an instance of the target class
    • safeCastOptional

      public static <T> Optional<T> safeCastOptional(Object obj, Class<T> clazz)
      Safely cast an object to the specified type, returning Optional.
      类型参数:
      T - The target type
      参数:
      obj - The object to cast
      clazz - The target class
      返回:
      Optional containing the casted object, or empty if cast fails