Class TypeLiteral<T>

java.lang.Object
cloud.opencode.base.reflect.type.TypeLiteral<T>
Type Parameters:
T - the type to capture | 要捕获的类型

public abstract class TypeLiteral<T> extends Object
Type Literal (Alternative to TypeToken) 类型字面量(TypeToken的替代)

A simpler alternative to TypeToken for capturing generic types. Similar to Commons Lang TypeLiteral.

用于捕获泛型类型的更简单的TypeToken替代方案。 类似于Commons Lang TypeLiteral。

Usage Examples | 使用示例:

TypeLiteral<List<String>> type = new TypeLiteral<List<String>>() {};
Type actualType = type.getType();

Features | 主要功能:

  • Generic type capture via anonymous subclass - 通过匿名子类捕获泛型类型
  • Raw type extraction - 原始类型提取
  • Type equality comparison - 类型相等比较

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Null-safe: No (must be created with type parameter) - 空值安全: 否(必须带类型参数创建)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • TypeLiteral

      protected TypeLiteral()
      Creates a TypeLiteral by capturing generic type 通过捕获泛型类型创建TypeLiteral
  • Method Details

    • getType

      public Type getType()
      Gets the captured Type 获取捕获的Type
      Returns:
      the Type | 类型
    • getRawType

      public Class<? super T> getRawType()
      Gets the raw type 获取原始类型
      Returns:
      the raw class | 原始类
    • toTypeToken

      public TypeToken<T> toTypeToken()
      Converts to TypeToken 转换为TypeToken
      Returns:
      TypeToken | TypeToken
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object