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

Type parameter deemed nullable in <? extends T> and nonnull in <T>? #6740

Open
MichalStehlikCz opened this issue Aug 6, 2024 · 0 comments
Open
Assignees

Comments

@MichalStehlikCz
Copy link
Contributor

MichalStehlikCz commented Aug 6, 2024

Following use case

public class Test {

  @Nullable Object item;

  <T> @Nullable T getNullable(Class<T> type) {
    return type.cast(item);
  }

  <T> Optional<T> getOpt(int index, Class<? extends T> type) {
    return Optional.ofNullable(getNullable(type));
  }
}

fails compilation in getOpt method with

java: [argument] incompatible argument for parameter type of Test.getNullable.
  found   : @Initialized @NonNull Class<capture#01 extends T extends @Initialized @Nullable Object>
  required: @Initialized @NonNull Class<T extends @Initialized @NonNull Object>

I believe it should compile fine, as neither method makes any assumption about nullity constraints on type variable

It compiled fine with 3.42.0, fails with 3.46.0

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

2 participants