import org.jetbrains.annotations.*;
import java.util.*;
import java.util.stream.Stream;
public class MethodReferenceConstantValue {
void testNonAnnotated() {
nonAnnotated(nullable());
Stream.of(nullable()).map(MethodReferenceConstantValue::nonAnnotated);
}
@Contract(value = "!null -> false", pure = true)
public boolean strangeMethod(String s) {
return s == null ? new Random().nextBoolean() : false;
}
@Contract(value = "_ -> true", pure = true)
private static boolean alwaysTrue(Object x) {
return true;
}
public void test(Optional opt) {
X x = MethodReferenceConstantValue::strangeMethod;
Boolean aBoolean = opt.map(this::strangeMethod)
.map(Objects::nonNull)
.map(Objects::isNull)
.map(MethodReferenceConstantValue::alwaysTrue)
.orElse(false);
if (opt.isPresent()) {
Stream.generate(opt::isPresent)
.limit(10)
.forEach(System.out::println);
}
}
public static native String nonAnnotated(String s);
@Nullable
public static native String nullable();
public void test(List<@foo.NotNull String> list) {
list.removeIf(Objects::isNull);
}
interface X {
boolean action(@Nullable MethodReferenceConstantValue a, @NotNull String b);
}
}