How to use @ConfigurationProperties with Records?

Answering my own question. The above error raises from Spring Boot not being able to construct the bean because of the lack of a no-argument constructor. Records implicitly declare a constructor with a parameter for every member. Spring Boot allows us to use the @ConstructorBinding annotation to enable property binding by constructor instead of setter … Read more

Switch expression with void return type

Maybe yield a Consumer of Event, so you yield something useful, the trade off is one more line for consumer.accept. Consumer<Event> consumer = switch (event.getEventType()) { case ORDER -> e -> handle((OrderEvent) e); case INVOICE -> e -> handle((InvoiceEvent) e); case PAYMENT -> e -> handle((PaymentEvent) e); }; consumer.accept(event); Continue if you concern performance Based … Read more

Differences of Java 16’s Stream.toList() and Stream.collect(Collectors.toList())?

One difference is that Stream.toList() provides a List implementation that is immutable (type ImmutableCollections.ListN that cannot be added to or sorted) similar to that provided by List.of() and in contrast to the mutable (can be changed and sorted) ArrayList provided by Stream.collect(Collectors.toList()). Demo: import java.util.stream.Stream; import java.util.List; public class Main { public static void main(String[] … Read more

Lombok’s access to jdk.compiler’s internal packages incompatible with Java-16

Update: Lombok v1.18.20 supports JDK 16 out of the box. In the same thread, one of the maintainers also writes: We have some less well known loopholes we can use to bridge a few gaps. We’ll start work on gradle and maven plugins in the mean time, which will be a long-term fix. Original: The … Read more