Dynamic Dispatch


Dynamic Dispatch

Dynamic Dispatch is the process used by the implementation of an object-oriented programming language to implement overriding, i.e., to allow a subclass to replace the behaviour of a method defined in a superclass.

For example, Dynamic Dispatch ensures that Java always calls the toString() method of the correct type (i.e., for Integer or NumberFormatException) in the code below:

String s = ...; Object a; try { a = Integer.valueOf(s); } catch (NumberFormatException e) { // not an int a = e; } System.out.println(a.toString());

A program analysis must thus be able to reason that the call a.toString() may call either String java.lang.Integer.toString() or String java.lang.NumberFormatException.toString().

A sound (but conservative) may-call analysis such as Class Hierarchy Analysis might e.g. report that a.toString() may call any toString() method in any Java class, though this imprecision may be detrimental to the quality of the call graph analyses' Client Analyses.