Type pattern and raw type

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Mar 19 18:52:47 UTC 2021

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 


More information about the amber-spec-experts mailing list