[code-reflection] RFR: 8374550: API for casting Value to Op.Result and Block.Parameter [v3]

Gary Frost gfrost at openjdk.org
Tue Jan 6 19:01:37 UTC 2026


On Tue, 6 Jan 2026 17:46:07 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> src/jdk.incubator.code/share/classes/jdk/incubator/code/Value.java line 95:
>> 
>>> 93:      */
>>> 94:     public Block.Parameter parameter() {
>>> 95:         if (this instanceof Block.Parameter p) {
>> 
>> as above, I think this is likley to trip folk up, calling this to get Parameter and having to deal with exception 
>> 
>> maybe asParameterorThrow. 
>> 
>> Again Paul can make the final call on this.
>
>> Again Paul can make the final call on this.
> 
> The approach taken was to keep in sync with the same [idiom](https://github.com/openjdk/jdk-sandbox/blob/json/src/java.base/share/classes/java/util/json/JsonValue.java#L249) proposed in the JSON API, and update as that updates when it is reviewed.
> 
> The rational for this idiom is they are like assertions, so any throwing indicates an incorrect program rather than something actionable the program would do when an exception is thrown, so that influenced the name. Otherwise, for conditional cases patterns can be used directly.
> 
> More generally we may be missing a language feature that supports assignment from a partial pattern as if it were total and throwing a match failed exception otherwise.

OK makes sense ;)

-------------

PR Review Comment: https://git.openjdk.org/babylon/pull/816#discussion_r2665964622


More information about the babylon-dev mailing list