Skip to content
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

@Nullable result inferred for @NonNull returning method #6756

Open
MichalStehlikCz opened this issue Aug 12, 2024 · 0 comments
Open

@Nullable result inferred for @NonNull returning method #6756

MichalStehlikCz opened this issue Aug 12, 2024 · 0 comments

Comments

@MichalStehlikCz
Copy link
Contributor

abstract class Test {

  abstract <T> @NonNull T get(Class<T> type);

  Collection<Map.Entry<String, String>> getEndpointMap(Stream<Test> tests) {
    return tests
        .map(val -> Map.entry(val.get(String.class), val.get(String.class)))
        .toList();
  }
}

compilation fails with

C:\Projects\pvyscomponents\java\libs\kernel\repository\api\src\main\java\com\provys\repository\Test.java:22:30
java: [return] incompatible types in return.
  type of expression: @Initialized @NonNull Entry<@Initialized @NonNull String, @Initialized @Nullable String>
  method return type: @Initialized @NonNull Entry<@Initialized @NonNull String, @Initialized @NonNull String>

It is a bit strange that if type arguments for Map.entry are specified in offending line, code compiles without warnings
.map(val -> Map.<String, String>entry(val.get(String.class), val.get(String.class)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant