Kbase P181411: Cannot overload method with only different return type
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  2/3/2011 |
|
Status: Unverified
SYMPTOM(s):
Cannot overload method with only different return type
Defining 2 methods with same name and same parameters but different return types
Class doesn't compile
Duplicate signatures found for method ''. (13842)
Following example shows issue:
CLASS test:
METHOD PUBLIC CHARACTER mytest():
END METHOD.
METHOD PUBLIC INT64 mytest():
END METHOD.
END CLASS.
FACT(s) (Environment):
All Supported Operating Systems
OpenEdge 10.1B
OpenEdge 10.1C
OpenEdge 10.2x
CAUSE:
This is expected behavior.
The ABL implementation of overloading was designed to mirror that of other popular OO languages (the Microsoft .NET languages, Java), which also do not allow overloading by return-type alone.
FIX:
Instead of differentiating the different overloads by return type, use an output parameter. Output parameters are taken into account in determining the method signatures, and will avoid duplicates.
Continuing from the example above, this class will compile succesfully:
CLASS test:
METHOD PUBLIC VOID mytest(OUTPUT cResult AS CHARACTER):
END METHOD.
METHOD PUBLIC VOID mytest(OUTPUT iResult AS INT64):
END METHOD.
END CLASS.