Error messages technically true but that does not help if several cases have the same erasure
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Jul 8 13:14:57 UTC 2021
On 07/07/2021 18:42, Remi Forax wrote:
> The same is true for
> List<?> list = null;
> switch (list) {
> case List l -> System.out.println("list2");
> case List<?> l -> System.out.println("list1");
> }
>
> which reports
> PatternMatchingWrongDominated.java:18: error: duplicate total pattern
> case List<?> l -> System.out.println("list1");
> ^
>
>
> I think javac should have a specific error if two cases have the same erasure.
I tend to agree, javac usually adds "detailed" messages, in parenthesis
after the main issue. So this could be:
```
PatternMatchingWrongDominated.java:18: error: duplicate total pattern
case List<?> l -> System.out.println("list1");
^
(List and List<?> have the same erasure)
```
Maurizio
More information about the compiler-dev
mailing list