Power JavaDynamic Binder

Power Java
Dynamic Binder

Mike Mannion

Listing 1.
Example implementation of the getCommand method.


    protected Command getCommand(Target t)
    {
        return getCommandForClass(t.getClass());
    }
    protected Command getCommandForClass(Class targetClass)
    {
        if (commandTable.containsKey(targetClass))
        {
            // Return Command most suitable for this class
            return (Command)commandTable.get(targetClass);
        }
        else
        if (targetClass.equals(java.lang.Object.class))
        {
            // This should never happen
            throw new RuntimeException(
                "No command found for class "+targetClass.getName());
        }
        // Return updater corresponding to superclass of this class
        return getCommandForClass( targetClass.getSuperclass() );
    }

Upcoming Training Events

0 AM
Visual Studio Live! San Diego
September 8-12, 2025
Live! 360 Orlando
November 16-21, 2025
Cloud & Containers Live! Orlando
November 16-21, 2025
Data Platform Live! Orlando
November 16-21, 2025
Visual Studio Live! Orlando
November 16-21, 2025