Skip to content

Clarify the use for print(List<@Nullable Object> values) vs print(List<? extends @Nullable Object>) #748

@vlsi

Description

@vlsi

I wonder if the following have the same or different semantics regarding nullness:

// Does this allow List<@NonNull Object> parameter?
void print(List<@Nullable Object> values) {
}

// I hope this should accept both List<@NonNull Object> and List<@Nullable Object> as well as List<String>
void print(List<? extends @Nullable Object> values) {
}

Based on my experience with checkerframework, I would say the second method is better typed, however, I was not able to understand the way jspecify would treat the arguments.

I was not able to find the documentation on usage of the annotations for method arguments when using generics: https://jspecify.dev/docs/user-guide/#generics

Could you please clarify which signature jspecify expects for a method that accepts a list of objects of any kind (nullable or not), including a list of objects that are definitely non-null?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions