# Is it OK to define an overloaded function?

Sometimes it would be quite useful in some languages to define two overloaded functions/methods as one answer. That is, instead of doing this (using Java as an example):

int f(Object o){if (o instanceof Integer) ... else if (o instanceof String) ...}


You would do this:

int f(Integer i){...}
int f(String s) {...}


In case of Java, you don't have to change to call site, but I'm not sure if this applies to all languages.

• Do you have an example of an existing question where you need to do this? If not, please avoid asking about unlikely hypothetical scenarios. – feersum Sep 29 '16 at 22:53
• This is common practice in Mathematica (although overloading semantics are a bit different there, but the effect is basically the same). – Martin Ender Sep 30 '16 at 5:15
• @feersum I'm asking because of this challenge. – corvus_192 Sep 30 '16 at 5:38