Question: Why Java not have an union type

B. Blaser bsrbnd at gmail.com
Sun Dec 20 14:31:41 UTC 2020


Hi,

On Fri, 11 Dec 2020 at 23:40, Netroby <hufeng1987 at gmail.com> wrote:
>
> For short, let's see the RFC document from the PHP community.
>
> https://wiki.php.net/rfc/union_types_v2

Union types are internally approximated with the least upper bound
(JLS15 §4.10.4) but the language exposes them in 'catch' clauses
though, see JLS15 §14.20:
"The declared type of an exception parameter that denotes its type as
a union with alternatives D 1 | D 2 | ... | D n is lub( D 1 , D 2 ,
..., D n )."

However, is someone else aware of any plan to use this syntax more
broadly in Java?

Regards,
Bernard


More information about the jdk-dev mailing list