heads-up: biggie overload rewrite

maurizio cimadamore maurizio.cimadamore at oracle.com
Fri Jul 26 11:31:11 PDT 2013


On 26-Jul-13 6:44 PM, Zhong Yu wrote:
> Signature of `m` is determined; type of `expr` is to be determined.
> Should we use the parameter type to constrain the argument type? Why
> not. I've seen many questions of this nature on stackoverflow.com. It
> is very surprising to programmers that the compiler cannot take
> advantage of knowledge of `m` to infer `expr`. It seems very
> reasonable to think that the method invocation is equivalent to
>      X x = expr;
>      m(x);
> I think this is definitely a deficiency of the language.
Except that X is generally used to infer the type of expr - as when you 
have

X x = m(new Foo<>);

One thing is to use X to infer a more precise information; of course we 
want that. And in fact it's just what the compiler does. Another thing 
is to ask X to influence the overload selection process. Currently 
that's how far we allowed target-typing to go, as we think it's a very 
subtle side-effect to have X influence which method is picked - one that 
can get really nasty in cases of multiply nested layers of calls. In 
such cases the compiler will ask user intervention, which, if seems more 
or less in line with what you are asking for at the end of you email 
(where you seem to advocate more explicit typing). I'm not saying that 
the above line cannot be moved, but there should be really strong 
arguments to support that.

Also, to put this into perspective, I honestly think that most of the 
cases mentioned in stackoverflow (at least the one I came across) will 
be addressed out of the box by what's already available in the 
compiler/language.

Maurizio




More information about the lambda-dev mailing list