Overload resolution simplification
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Wed Aug 14 03:29:44 PDT 2013
On 14/08/13 10:57, Maurizio Cimadamore wrote:
> but it would seems that C# can use the target-type information _ahead_
> of overload resolution to perform inference, thus being able to reject
> applicable candidates based on return mismatch (which Java cannot do).
This is incorrect - I found this [1] which clearly states (Eric Lippert)
that by design, in C# type information flows from argument types
outwards, not the other way around. This means that several examples
discussed in this mailing list wouldn't work in C# too, especially the
ones around Comparator.comparing - in that case in fact, the only way to
type-check the lambda is to instantiate the formal parameter of the
method with the information that's available from the target-type
context. Java won't do it because that would break the invariant that
overload selection should not depend on target type. It seems like C#
has a similar (sensible) restriction.
[1] -
http://stackoverflow.com/questions/3203643/generic-methods-in-net-cannot-have-their-return-types-inferred-why
Maurizio
More information about the lambda-spec-observers
mailing list