Fix for ClassCastException with polymorphic middle binding