On 31/10/2020 23:30, Brian Goetz wrote:


On Oct 25, 2020, at 10:06 AM, Brian Goetz <brian.go...@oracle.com <mailto:brian.go...@oracle.com>> wrote:

To make it clear that I'm not talking about the annoyance of typing the cast, let's pretend I'm suggesting to write it like this:

    BarImpl bi = (__static BarImpl) b;

Pulling on this string some more — I think there’s a connection between this feature and total statement switches.  We’ve been looking for a way to make statement switches total, and here, what we’re looking for is a way to make _casts_ total.  Which suggests this is one feature, not two.  So perhaps:

    switch-total (x) { … }  // a switch, but with added bonus totality checking

    BarImpl b = (total BarImpl) bar  // a cast, but with added bonus totality checking

I agree the latter is a common enough problem when writing implementation code where you have a sealed hierarchy and you know there's only one impl (Foreign API has this all over the place).

To throw in the mix - how is some kind of pattern match assignment (we referred to as a "let expression" in some of the earlier docs [1]) would change the picture here? In other words, maybe it's overloading `=` which is at odds here, and we need to make it more explicit that this is more akin to an extraction/match?

Maurizio

[1] - https://cr.openjdk.java.net/~briangoetz/amber/pattern-semantics.html


Obviously we can use another word besides `total`, but it’s a pretty good straw man.


Reply via email to