Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/replaceWithTrivialLambda/beforeMethodRef.java
Tagir Valeev 6ffb7e417e [java-dfa] Extract "Constant conditions" into separate "Constant values" inspection (IDEA-58235)
GitOrigin-RevId: 95a81fcd1546afec31afc2a044a9ba5fa1337411
2022-09-08 21:30:59 +00:00

29 lines
840 B
Java

// "Fix all 'Constant values' problems in file" "true"
import org.jetbrains.annotations.*;
import java.util.*;
import java.util.stream.Stream;
public class MethodReferenceConstantValue {
@Contract(value = "!null -> false", pure = true)
public boolean strangeMethod(String s) {
return s == null ? new Random().nextBoolean() : false;
}
public void test(Optional<String> opt) {
X x = MethodReferenceConstantValue::strangeMethod;
Boolean aBoolean = opt.map(th<caret>is::strangeMethod)
.map(Objects::nonNull)
.map(Objects::isNull)
.orElse(new Random().nextBoolean());
if (opt.isPresent()) {
Stream.generate(opt::isPresent)
.limit(10)
.forEach(System.out::println);
}
}
interface X {
boolean action(@Nullable MethodReferenceConstantValue a, @NotNull String b);
}
}