Меня очень раздражает синтаксис method reference (где
::). Я решительно не понимаю, зачем он нужен и на мой взгляд он ухудшает читаемость кода. Хотелось бы услышать стороннее мнение. Приведу несколько фрагментов кода.
appointmentRepository.queryByIds(appointmentIds).stream()
.filter(Objects::nonNull)
appointmentRepository.queryByIds(appointmentIds).stream()
.filter(appointment -> nonNull(appointment))
appointmentRepository.queryByIds(appointmentIds).stream()
.filter(appointment -> appointment != null)
`
Set<String> acceptedIins = response.stream()
.map(SomeApiClient.AddReferrersResponseItem::getIin)
.collect(toSet());
Set<String> acceptedIins = response.stream()
.map(responseItem -> responseItem.getIin())
.collect(toSet());
Я предполагаю, что method reference может компилироваться в незначительно более быстрый код, но уверен, что разница неизмерима на практике.