New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generic userdoc confusion #500
Comments
Ha that is a good find!
No. It is whatever the declaration is. Let us assume we are in code bases with NullMarked. List<String> list = ...;
var e = list.get(0); // e is nonnull here. and List<@Nullable String> list = ...;
var e = list.get(0); // e is nullable here. Again assuming a public interface List<E> { Means E is always nonnull. I guess you could think of it as public class ImmutableList<@Nullable E> { I assume the above implements our nonnull List of The tools currently will allow it but I think in JSpecify in spirit should be an error. |
so why do this? Also, what happens if you have
yes, although, that is a good example of maybe why the examples shouldn't be |
...lets users write both That's in contrast to...
...which would allow only "one kind" of I have a doc that has a list of types to demonstrate when various combination of nullnesses may be useful for generic types. Here's a snippet: @NullMarked
interface Factory<T extends @NonNull Object> {
T newInstance();
}
@NullMarked
interface BlockingQueue<E extends @NonNull Object> {
@Nullable E peek();
}
@NullMarked
interface Supplier<T extends @Nullable Object> {
T get();
}
@NullMarked
interface NavigableSet<E extends @Nullable Object> {
@Nullable E pollFirst();
}
As noted, we define that as an inapplicable location for
Guava actually has one weird type like that,
The type would be inferred from the right-hand side of the assignment (e.g., |
(And yes, the real thing we need to do here is to improve our docs.) |
Sort of off topic but I guess I missed that Was it always available? I swear its not in JSpecify 0.3. EDIT I guess I missed it: https://github.com/jspecify/jspecify/releases |
Now that I'm looking at the Javadoc of NonNull a note should probably be added either below or addition to:
That you should not combine the I'm not even sure what checker does in that case but I assume its an error. I'll check later (pun intended). EDIT never mind. I'm slow today I see it now on Nullable javadoc:
|
Well, I was about to boldly claim that " |
Looking at the first example
is
E get(int index);
automatically@Nullable
here?what if
List
were defined asand then
would
E get(
onImmutableList
automatically be nullable?P.S. the docs say that
getFirst
is fictitious which is no longer true as of java 21.The text was updated successfully, but these errors were encountered: