If you provide a function, this function should work with its arguments, i.e.
final String longestString = observed.accumulateAndGet(x,
maxBy((str1, str2) -> observed.get().length() - x.length()));
API. accumulateAndGet , get .
, , :
final String longestString = observed.accumulateAndGet(x,
maxBy((str1, str2) -> str1.length() - str2.length()));
final String longestString =
observed.accumulateAndGet(x, maxBy(comparingInt(String::length)));
, - , , , accumulateAndGet , , accumulateAndGet. AtomicReference . - String , .
, , .
, :
public static String updateLongestString(AtomicReference<String> observed, String x) {
final String longestString = observed.accumulateAndGet(x, maxBy((str1, str2) -> {
LOGGER.info("Received str1: {}, str2: {}", str1, str2);
return str1.length() - str2.length();
}));
LOGGER.info("New observed: {}.", longestString);
return longestString;
}