如何防止调用 class 层次结构中的所有 'onEvent' 方法
How to prevent calling all 'onEvent' methods in class hierarchy
我正在努力防止调用 class 层次结构链中的所有方法。
假设我有一个 base class:
class BaseModel
{ /* Some basic fields goes here */ }
class ModelCompany extends BaseModel
{ /* Fields goes here */ }
然后我想post两个不同的事件:
BaseModel oneEvent = new BaseModel();
ModelCompany otherEvent = new ModelCompany();
EventBus.getDefault().post(oneEvent);
EventBus.getDefault().post(otherEvent);
activity中的某处:
onEvent(BaseModel ev1){}
onEvent(ModelCompany ev2){}
问题是在这种情况下将执行两个 onEvent 方法。如何防止它和 post 消息到确切的方法?
在 EventBus 3 中可以使用 EventBusBuilder.eventInheritance()
我正在努力防止调用 class 层次结构链中的所有方法。 假设我有一个 base class:
class BaseModel
{ /* Some basic fields goes here */ }
class ModelCompany extends BaseModel
{ /* Fields goes here */ }
然后我想post两个不同的事件:
BaseModel oneEvent = new BaseModel();
ModelCompany otherEvent = new ModelCompany();
EventBus.getDefault().post(oneEvent);
EventBus.getDefault().post(otherEvent);
activity中的某处:
onEvent(BaseModel ev1){}
onEvent(ModelCompany ev2){}
问题是在这种情况下将执行两个 onEvent 方法。如何防止它和 post 消息到确切的方法?
在 EventBus 3 中可以使用 EventBusBuilder.eventInheritance()