Details
-
Improvement
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
A method which always returns an instance of class C can be specified in the API to return an instance of C or any of its superclasses. Change the return type to be C instead of one of the superclasses, because
- the user who is expecting the supertype will still work and cost nothing (a "Widening Reference Conversion")
- users who need the subtype would otherwise need to cast back to the subtype - which is a runtime check (unless the JIT can optimize this away).