Intersection and Union Types for Java

Brian Goetz brian.goetz at oracle.com
Wed Jan 20 14:37:25 UTC 2021


It surely *can*; evidence is here: 
https://scholarship.rice.edu/handle/1911/103594

The real question (and this is always the case) is whether we should.  
As you point out, there is clearly a nonzero benefit. But doing so is a 
complex endeavor, full of tradeoffs.  Spending the at-least-a-thousand 
expert-hours on this, means that effort is not available to do something 
else, whose benefit might be dramatically more.  And we have a limited 
budget for asking users to absorb new language complexity; this may not 
be the best place to spend that.

So yes, it could, but it's been a deliberate choice not to, because 
there are other places we can better expend that effort.

On 1/20/2021 1:53 AM, Suminda Sirinath Salpitikorala Dharmasena wrote:
> Hello,
>
> Can the Java type system be extended to accommodate Intersection and 
> Union Types.
>
> Currently we can write:
>  <T extends A & B> void f(T t) { ... }
>
> but not
>
>  <T extends A | B> void f(T t) { ... }
>
> or
>
>  <T extends (A | B) & C> void f(T t) { ... }
>
> Also we cannot have
>
>    void f(A & B t) { ... }
>
> or
>
>    void f((A | B) & C t) { ... }
>
> When considering languages like Ceylon (https://ceylon-lang.org/ 
> <https://ceylon-lang.org/>) and Scala 3 / Dotty 
> (https://dotty.epfl.ch/ <https://dotty.epfl.ch/>) these seem to be 
> very useful.
>
> Suminda

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20210120/da41e4cf/attachment.htm>


More information about the compiler-dev mailing list