You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Possible uses for annotating an unbounded wildcard: Foo<@NullnessAnnotation ?> #88
Schemes where a wildcard might be annotated separately from its bound are discussed in #31, and I think we're in some stage of ruling those out. In this issue I want to consider whether we should support limited cases of annotating a wildcard, only when there is no provided bound.
Assume we say "no" to #85 (because I assume if we said yes it will dictate what we must do here).
Suppose we have class Foo<T extends @Nullable Base>.
Foo<@NonNull ?>could be a shorthand for Foo<? extends @NonNull Object> or Foo<? extends @NonNull Base>. It's now a reifiable type (is that good?), it's shorter, and it doesn't involve either redundantly writing Base (latter) OR strangely implying that the wildcard is bounded by Object when it really isn't (former). It could be thought of as a "type projection" of a wildcard (Non-null projection of a type variable usage #86) and that seems fairly okay.
Foo<@Nullable ?>could do the analogous thing, but here there is actually a big problem: it fails to emphasize the "might be nullable, might be non-null" meaning and will be taken erroneously by many users as being definitely-nullable. But if we decide Nullness bound for unbounded wildcard in a nullness-annotated context #83 in the way we're starting to lean (the ? in Foo<?> is implicitly nullable) then there won't be a reason to write this anyway.
To me, reasonable options seem to include allowing neither form, or allowing only the first one.
Activity
kevinb9n commentedon Dec 12, 2019
With
Foo<@NonNull ?>being, as far as the compiler is concerned, reifiable, we should be able to write an array typeFoo<@NonNull ?>[]warning-free. But see https://bugs.openjdk.java.net/browse/JDK-8233945kevinb9n commentedon Dec 18, 2019
Is this a case where we can safely go with "allow neither" for now, and we're still free to consider adding it on in the future?
kevinb9n commentedon Jan 10, 2020
I'll answer my own question then: yes, it is. Current plan should be to not do this, but we have potential to offer a shorthand in the future.