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.

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

Yes, that's perfectly fine.

I could see this being useful for the recent challenge that requires different outputs based on if the input is an integer or a float/decimal.

| |
  • \$\begingroup\$ Yes, I had that exact question in mind. \$\endgroup\$ – corvus_192 Sep 30 '16 at 5:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .