Kbase P147769: Error 12950 appears when a method has been overridden changing the return data type
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  6/17/2009 |
|
Status: Unverified
SYMPTOM(s):
Error 12950 appears when a method has been overridden just by changing the return data type
already defined in inherited class with return type.(12950)
FACT(s) (Environment):
Windows
OpenEdge 10.2A
CAUSE:
This is expected behavior: when a class overrides a method defined in a super class, the override method must have the same signature as the method defined in the super class. The return type, number of parameters, and data types and modes of the parameters must all be the same.
FIX:
The return type is part of the signature, and that is why it cannot be changed. Overwritten methods could return any derived types, but the caller has to receive it as the more generic one declared on the base class. For example:.
Class a
Method meth1 returns GenericType.
Class b inherits a
Method meth1 returns GenericType. (Overwritten).
Class type A could point to objects from A and B, and still being able to call the method meth1 that has to have the very same signature in both classes.
However, it is not possible to overload methods by differentiating only the return type. For example:
Class a
Method1 returns int.
Method1 returns long.
In the case above, if the code contains something like object:method1, it is impossible to determine which one to call, and even if it is changed to be longVar = object:method1, it is still impossible because a long can accommodate a int.
Therefore, in order to override a method, the signature in the subclass must match the super class exactly (with the possible exception of a less restrictive access modifier). When overloading a method, the overloaded methods cannot differ by only return type or access modifier.
If using the same method with different return types is needed, it is possible to cast the return value in the caller to the desired type. Presumably the caller knows the type it wants to get back so it can call a single method and cast it to the expected type.