Skip to content

Revisit nullness of Collectors.toMap #147

Description

@cpovirk

It looks like we have the key types as nullable but the value type not? I would have guessed that they'd both be nullable.

I wonder if part of the story here is that the ones that declare a mergeFunction would want a non-null type argument there? But, if so:

  • We could accomplish that with @NonNull.
  • It's not clear to me that a nullable type argument there would be wrong, just potentially inconvenient in some cases (and convenient in others).

I'm belatedly realizing that a Guava user had raised a related question before in google/guava#6824. So part of the story might be that a more flexible signature has been difficult for some tools in the past. But I know that the Checker Framework improved its type inference a while back, so we should get some real-world data on this once we're able to import those changes to Google's monorepo.

(I noticed this as I was putting together #146.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions