Class DataEvent<T>

java.lang.Object
cloud.opencode.base.event.Event
cloud.opencode.base.event.DataEvent<T>
Type Parameters:
T - the type of data payload | 数据载荷类型

public class DataEvent<T> extends Event
Generic Data Event 泛型数据事件

Event that carries typed data payload.

携带类型化数据载荷的事件。

Features | 主要功能:

  • Type-safe data payload - 类型安全的数据载荷
  • Immutable data reference - 不可变数据引用
  • Generic type support - 泛型类型支持

Usage Examples | 使用示例:

// Create data event
Order order = new Order(1L, "Product");
DataEvent<Order> event = new DataEvent<>(order, "OrderService");

// Publish
OpenEvent.getDefault().publish(event);

// Listen
OpenEvent.getDefault().on(DataEvent.class, e -> {
    Order data = (Order) e.getData();
    System.out.println("Received: " + data);
});

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
Since:
JDK 25, opencode-base-event V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • DataEvent

      public DataEvent(T data)
      Create data event with payload 创建带载荷的数据事件
      Parameters:
      data - the data payload | 数据载荷
    • DataEvent

      public DataEvent(T data, String source)
      Create data event with payload and source 创建带载荷和来源的数据事件
      Parameters:
      data - the data payload | 数据载荷
      source - the event source | 事件来源
  • Method Details

    • getData

      public T getData()
      Get the data payload 获取数据载荷
      Returns:
      the data | 数据
    • getDataType

      public Class<?> getDataType()
      Get the data type 获取数据类型
      Returns:
      the data class or null | 数据类型或null
    • toString

      public String toString()
      Overrides:
      toString in class Event