Skip to content

Better support method reference parameters in generic method inference #1307

Closed

Description

@agrieve

A variant of #1290:

@NullMarked
class Foo {
  interface Callback<T extends @Nullable Object> {
    void onResult(T thing);
  }

  void receiver(Callback<@Nullable Object> value) {
  }

  void target(@Nullable Object thing) {
  }

  public <T extends @Nullable Object> Callback<T> makeCancelable(Callback<T> callback) {
    return callback;
  }

  void main() {
    receiver(makeCancelable(this::target));
  }
}

results in:

Foo.java:21: warning: [NullAway] incompatible types: Callback<Object> cannot be converted to Callback<@Nullable Object>
    receiver(makeCancelable(this::target));
                           ^
    (see http://t.uber.com/nullaway )

An explicit cast will work-around it:

  void main() {
    receiver(makeCancelable((Callback<@Nullable Object>) this::target));
  }

Activity

  1. added
    jspecify
    on Oct 16, 2025
  2. added a commit that references this issue on Jan 7, 2026
  3. added a commit that references this issue on Jan 14, 2026
    d594809
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

    bugjspecify

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions