Open mches opened 1 month ago
An expression lambda like s -> b.append("/").append(s) can't be converted to a method reference because b.append("/") has a side effect
s -> b.append("/").append(s)
b.append("/")
String a = null; StringBuilder b = new StringBuilder(); Optional.ofNullable(a).ifPresent(s -> b.append("/").append(s)); System.out.println(b);
Output:
↓↓↓
String a = null; StringBuilder b = new StringBuilder(); Optional.ofNullable(a).ifPresent(b.append("/")::append); System.out.println(b);
/
Seems safer to assume a call chain produces a side effect and give up on converting such a lambda expression to method reference.
Fixed in https://github.com/solven-eu/cleanthat/pull/849
Bravo! 👏🏻
An expression lambda like
s -> b.append("/").append(s)
can't be converted to a method reference becauseb.append("/")
has a side effectOutput:
↓↓↓
Output:
Seems safer to assume a call chain produces a side effect and give up on converting such a lambda expression to method reference.