Skip to content

JSpecify: Integrate method reference types with generic method type inference #1431

Closed

Description

@msridhar

Example:

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import java.util.function.Function;
@NullMarked
class Test {
  interface Foo {
    default String get() {
      throw new RuntimeException();
    }
    default @Nullable String getNullable() {
      return null;
    }
  }
  private <T extends @Nullable Object> T create(Function<Foo, T> factory) {
    return factory.apply(new Foo() {});
  }
  void test() {
    String s1 = create(Foo::get);
    s1.hashCode(); // should be legal
    String s2 = create(Foo::getNullable);
    // BUG: Diagnostic contains: dereferenced expression s2 is @Nullable
    s2.hashCode();
  }
}

Generic method inference should infer that the first call to create returns a @NonNull String and the second call to create returns a @Nullable String based on the respective return types of Foo#get and Foo#getNullable.

Activity

  1. added
    jspecify
    on Jan 8, 2026
  2. added a commit that references this issue on Apr 3, 2026
    cf60f58
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

    jspecify

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions