[External] : Re: Diamond in type patterns (was: Reviewing feedback on patterns in switch)

Brian Goetz brian.goetz at oracle.com
Thu Jan 27 13:04:35 UTC 2022


It's more an engineering thing here, we have far more casts than switch + pattern in existing code, and given that we suppose (perhaps wrongly) that the semantics of the inference is not exactly one already existing,

I’d like to drill into this supposition.  My supposition (maybe wrong) is that we already solved most of this when we did `var`, with upward projection.

To recap, we spent a lot of time with `var` on what to do about non-denotable types.  These included the null type (banned on the grounds of uselessness), intersection types (allowed), and capture types (sanitized with upward projection.)  The basic idea of upward projection is that when we infer List<cap>, we replace it with a super type that has no capture types, and get List<?> out.  (There’s also a downward projection.)

Let’s start with your examples of where ordinary inference produces an undesirable result, and then evaluate whether either or the projections solves the problem?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20220127/97948723/attachment.htm>


More information about the amber-spec-experts mailing list