Why can't a dispatcher see a private handler method in a superclass?
← Dispatcher Validation · Ref: Q849
When a subclass has a dispatcher, it searches the superclass for matching handler methods. Private methods in the superclass are invisible. Use protected instead.
See Q616 for dispatcher ambiguity. See Q621 for dispatch rules.
Example
defines module qa.dispatcher.private.super defines class BaseHandler as open protected process() -> arg0 as Integer require arg0? default operator ? SubDispatcher extends BaseHandler process() as dispatcher -> arg0 as Any require arg0? runDemo() this.process(42) default operator ? defines function DispatcherDemo() handler <- SubDispatcher() handler.runDemo() require handler?
Common mistakes
E05180 — Private methods in a superclass are invisible to subclass dispatchers. Use protected. See ek9 -h E05180 for details.
Incorrect:
private process() -> arg0 as Integer require arg0?
Correct:
protected process() -> arg0 as Integer require arg0?
Other ways to ask this
- What triggers E05180 DISPATCHER_PRIVATE_IN_SUPER?
- Why must dispatcher handler methods be protected or public?
- How do I fix private dispatcher handler visibility?
Coming from another language?
Java: Visitor pattern requires public. C#: dynamic dispatch ignores private. EK9: compile-time error if dispatcher handler is private in super.
Keywords: dispatcher, protected, E05180, handler, private, super