import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; interface NonnullInterface { @NotNull String nonNullMethod(); } class P2 { private void callTest() { test(new NonnullInterface() { @Nullable @Override public String nonNullMethod() { return null; } }); test(this::getNull); test(this::getNonAnnotated); } @Nullable String getNull() { return null; } String getNonAnnotated() { return null; } private void test(final NonnullInterface function) { } }