mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-17 07:20:53 +07:00
27 lines
826 B
Java
27 lines
826 B
Java
// "Convert variable 'res' from String to StringBuilder (null-safe)" "true-preview"
|
|
|
|
import java.util.Optional;
|
|
|
|
public class Main {
|
|
String test(String[] strings) {
|
|
StringBuilder res = null;
|
|
for (String s : strings) {
|
|
if(res == null) {
|
|
res = Optional.ofNullable(s.isEmpty() ? null : s).map(StringBuilder::new).orElse(null);
|
|
} else {
|
|
res.append(", ").append(s);
|
|
}
|
|
res = (res == null ? new StringBuilder("null") : res).append(", ");
|
|
res.append(s);
|
|
}
|
|
System.out.println(res);
|
|
consume(res.toString());
|
|
return res.toString(); // known to be not-null at this point
|
|
}
|
|
|
|
// NotNull parameter inferred
|
|
static void consume(String s) {
|
|
System.out.println(s.trim());
|
|
}
|
|
}
|