[SalesForce] Overloading method return type in Apex

Does Apex support method return type overloading ?

I mean can I have a method in a class that return different type depending on it's Inputs ?

Best Answer

Yes, if the method signature is different you can have a different return type

In a class you can have

Integer add(Integer) 
String add(String) 

But you can't have

Integer add(Integer)
String add(Integer)

A working example :

public class myClass {

  public Integer add(Integer num){
    return null;
  }

  public String add(String str){
    return null;
  }

}