More comprehensive type inference for pattern matching
Nir Lisker
nlisker at gmail.com
Thu Oct 10 08:04:00 UTC 2024
Hi,
Give a simple generic wrapper,
class Container<T> {
T item;
}
pattern matching can find out what T is for 'item', but not for its
container:
void switchItem(Container<?> container) {
if (container.item instanceof Number num) {
acceptNumber(num);
acceptNumberContainer(container); // error
}
}
The information is technically there to make the derivation. I can envision
some complexities with bound constraints, but seeing as I can't check
'instanceof Container<Number>`, can the compiler not be smarter?
- Nir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241010/3d3d9ead/attachment.htm>
More information about the amber-dev
mailing list