Replace reflection with instanceof check on instance.