Proposal: Improved Type Inference for Generic Instance Creation

Joseph D. Darcy Joe.Darcy at Sun.COM
Sat Feb 28 00:02:29 PST 2009


Jeremy Manson wrote:
> Hey Neal,
>
> I think you might have missed where I asked for an example where G1
> and G2 might have different numbers of type parameters or they might
> have corresponding parameters in a different order.  I'm probably
> missing a very obvious example, and I'm sure you have an example in
> mind.
>
> On Fri, Feb 27, 2009 at 11:33 PM, Neal Gafter <neal at gafter.com> wrote:
>   
>> Adding conversions doesn't make type inference work.  Each conversion
>> that you want to affect type inference has to be accommodated
>> specifically in the type inference algorithm.
>>     
>
> I wasn't suggesting that adding conversions would make type inference
> work.  I was suggesting that the conversion could be done in place of
> the type inference.
>
>   
>> I disagree with your suggestion that this should fail:
>>
>>     List<?> list = new ArrayList<>(); // should fail
>>
>> The equivalent code using static factories works just fine.  It isn't
>> clear why this feature should behave differently, or what part of your
>> specification makes it fail.
>>     
>
> Basically, because I specifically disallowed wildcards under the
> sample spec.  See the second bullet point under "Semantics and
> Compilation".  However, I wasn't convinced that that was a good idea
> either, which is why I put it under Additional Features (at the end).
> The described technique under that header would make this example work
> (probably -- I'd have to double-check the JLS).
>
>   
>> I don't think supporting casts adds value to the feature.  You can
>> already assign, for example, from ArrayList to List<String> without a
>> cast.
>>     
>
> That was where Josh was leaning when I asked him about it, too.  The
> reason I thought it made sense was just for consistency's sake;
> basically, it is the only one of the five conversion contexts where
> this technique might work, but it doesn't.  For assignments and method
> parameters, it will work, and for String and numeric conversions, it
> doesn't make any sense.  Casting was the only one left.
>
>   
>> If you want to hear about the approach that Joe is working on, I'll be
>> happy to describe it in person at your convenience (with Joe, if he
>> wants).
>>
>>     
>
> I would definitely like to hear about it!  How close is Joe to
> finishing a draft?
>   

Joe hasn't started a draft!

Neal and I discussed some implementation strategies that could also 
guide a specification.  I'll send out more in the next few days.

Good night,

-Joe



More information about the coin-dev mailing list