Type pattern and raw type
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Mar 22 11:01:57 UTC 2021
On 22/03/2021 10:05, Gavin Bierman wrote:
> Agreed, Maurizio. Jan has pushed a patch for this. Now if you compile with `-Xlint:rawtypes` you’ll get a warning for `o instanceof Foo foo` - this was just an oversight.
Thanks for the clarification
Maurizio
>
> Gavin
>
>> On 19 Mar 2021, at 18:52, Maurizio Cimadamore <maurizio.cimadamore at oracle.com> wrote:
>>
>>
>> On 15/03/2021 13:28, Brian Goetz wrote:
>>> Unchecked conversions are forbidden because of type pollution, that why you can not write
>>> if (o instanceof Foo<Integer> foo) {
>>>
>>> Raw type conversions also leads to type pollution, so i think that a type pattern with a raw type should be forbidden too.
>> Note sure I agree here - they are two very different kind of pollutions.
>>
>> In the Foo<Integer> case the issue is that we might any type that converts to Foo<Integer> to be treated as a Foo<Integer>. E.g. Foo<? extends Number> -> Foo<Integer>. That is unsound, and the unsoundness happens in the conversion itself.
>>
>> But when you say `o instanceof Foo f`, you are not introducing any pollution. The pollution will be introduced when (and if) the raw type will be accessed.
>>
>> Honestly, I'm not even sure this deserves a warning (other than the customary "raw-type usage" warning - not an "unchecked" warning, to be clear).
>>
>> Maurizio
>>
More information about the amber-spec-experts
mailing list