Surprised that TYPE_USE annotations are accepted on `var` lambda parameters
Chris Povirk
cpovirk at google.com
Wed Oct 19 11:09:07 UTC 2022
>
> Since type-use annotations are rejected on var local variables, I would
> have expected them to be rejected on var lambda parameters, too.
>
That position fits with the idea that, when we use var, we're expecting the
full type to be inferred.
In contrast, if it *were* possible to put annotations on var, there would
be ambiguity about what the *absence* of an annotation means: Does it mean
"Please infer whether an annotation should be present on the inferred
type," or does it mean "Behave as if no annotation is present on the
inferred type?"
The conservative approach for developers would be to annotate *every* var
declaration. But, in addition to being verbose, that approach is possible
for our nullness work only if every type is either nullable or non-null—and
that's not the case, since a type-variable usage T has a nullness that will
depend on the type argument.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20221019/f4f8593b/attachment.htm>
More information about the compiler-dev
mailing list