Annotation Interface Subscribe


@Target(METHOD) @Retention(RUNTIME) public @interface Subscribe
Subscribe Annotation 订阅注解

Marks a method as an event subscriber.

标记方法为事件订阅者。

Requirements | 要求:

  • Method must have exactly one parameter - 方法必须只有一个参数
  • Parameter type must be Event or subclass - 参数类型必须是Event或其子类
  • Method can be any visibility - 方法可以是任意可见性

Usage Examples | 使用示例:

public class UserEventHandler {
    @Subscribe
    public void onUserRegistered(UserRegisteredEvent event) {
        // Handle user registration
    }

    @Subscribe
    @Async
    public void onUserRegisteredAsync(UserRegisteredEvent event) {
        // Handle asynchronously
    }

    @Subscribe
    @Priority(100)
    public void onUserRegisteredFirst(UserRegisteredEvent event) {
        // Handle with high priority
    }
}

// Register the handler
OpenEvent.getDefault().register(new UserEventHandler());

Features | 主要功能:

  • Core functionality - 核心功能

Security | 安全性:

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