You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, when I try filter(Objects::nonNull) to filter out any null value and then use map to apply a lambda, the checker framework seems to complain about the incompatible receiver type, here's a simple test example:
@Test
void test() {
List<@Nullable String> s = new ArrayList<>();
s.add("abc");
s.add(null);
s.add("cdf");
System.out.println(s.stream().filter(Objects::nonNull).map(String::length).toList());
}
And I got the following error:
error: [methodref.receiver] Incompatible receiver type
System.out.println(s.stream().filter(Objects::nonNull).map(String::length).toList());
^
found : @Initialized @NonNull String
required: @Initialized @Nullable String
Consequence: method in @Initialized @NonNull String
@Initialized @NonNull int length(@Initialized @NonNull String this)
is not a valid method reference for method in @Initialized @NonNull Function<@Initialized @Nullable String, @Initialized @NonNull Integer>
@Initialized @NonNull Integer apply(@Initialized @NonNull Function<@Initialized @Nullable String, @Initialized @NonNull Integer> this, @Initialized @Nullable String p0)
Is this a correct behavior? How can I make the code work?
The text was updated successfully, but these errors were encountered:
Hi, when I try
filter(Objects::nonNull)
to filter out any null value and then usemap
to apply a lambda, the checker framework seems to complain about the incompatible receiver type, here's a simple test example:And I got the following error:
Is this a correct behavior? How can I make the code work?
The text was updated successfully, but these errors were encountered: