Understand Java Visitor double dispatch so the chosen visit method depends on both the element type and the visitor type.
Visitor relies on double dispatch: the operation selected depends on both the element being visited and the visitor performing the operation.
flowchart LR
A["Client calls element.accept(visitor)"] --> B["Element runtime type chooses accept implementation"]
B --> C["accept calls visitor.visitSpecificElement(this)"]
C --> D["Visitor runtime type chooses concrete visit behavior"]
That two-step dispatch is what lets Java simulate richer type-directed operation selection than one ordinary virtual call would provide.
Without understanding double dispatch, Visitor looks like unnecessary ceremony. With it, the pattern’s purpose becomes clearer: route operations by actual element type without stuffing all operations into the element hierarchy.