Question: Why Java not have an union type

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


On Fri, 11 Dec 2020 at 23:40, Netroby <hufeng1987 at> wrote:
> For short, let's see the RFC document from the PHP community.

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?


More information about the jdk-dev mailing list