mP.*_*mP. 6 java api class-design class
首先是 - 这是主观的.
我最近注意到一些库似乎使用让某些类中的用户标记侦听器方法作为侦听器使用不同的注释来记录不同的事件.作为这种方法的例子,我想到了Infinispan和WELD.
我讨厌这种模式
可能的原因
意见
那么为什么有人想要使用这种方法呢?我个人没有得到它,它似乎为实现者做了更多的工作,使用户的生活更加艰难,速度更慢,为什么要使用它呢?
我使用这种方法来让侦听器可以接受特定类型、接口(这意味着所有类都实现该接口)以及其中之一的数组。
例如
// called for each MyRecord
@Listener
public void onMyRecord(MyRecord r);
// when a batch of MyRecord is published,
// call this method on the swing event thread.
@Listener(swing=true)
public void onMyRecords(MyRecord... rs)
// Listeners can have priority to determine the order of multiple listeners
// Called when any number of events are published with a priority of 5.
@Listener(priority=5)
public void onIMyEvent(IMyEvent ... events)
Run Code Online (Sandbox Code Playgroud)