A safe implementation of dynamic overloading in Java-like languages