Does introducing a default method to an interface really preserve back-compatibility?

Although adding a default method with the same name in the two interfaces would make the code fail to compile, but once you resolve the compilation error, the binaries obtained after compiling both the interfaces, and the class implementing the interfaces, would be backward compatible. So, the compatibility is really about binary compatibility. This is … Read more

How to persist LocalDate with JPA?

With JPA 2.2, you no longer need to use converter it added support for the mapping of the following java.time types: java.time.LocalDate java.time.LocalTime java.time.LocalDateTime java.time.OffsetTime java.time.OffsetDateTime @Column(columnDefinition = “DATE”) private LocalDate date; @Column(columnDefinition = “TIMESTAMP”) private LocalDateTime dateTime; @Column(columnDefinition = “TIME”) private LocalTime localTime;

Convenient way of checking equality for Optionals

You have many options. Already noted: boolean isEqual = maybeFoo.equals(Optional.of(testFoo)); Alternatively: boolean isEqual = maybeFoo.isPresent() && maybeFoo.get().equals(testFoo); Or: boolean isEqual = testFoo.equals(maybeFoo.orElse(null)); These last two do have slightly different semantics: each returns a different value when maybeFoo is empty and testFoo is null. It’s not clear which is the correct response (which I guess is … Read more

Will x64 jdk-1.8 work in Mac with Apple Silicon (M1) Chip?

Homebrew does not support OpenJDK@8 on Apple Silicon (M1/M2) but Zulu Community 8 is present as a cask. You just have to enable cask-versions repository and install zulu8 cask. brew tap homebrew/cask-versions brew install –cask zulu8 It will install the JDK in /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home. You should then configure your JAVA_HOME variable for development tools to use … Read more

Can I not map/flatMap an OptionalInt?

Primitive optionals haven’t map, flatMap and filter methods by design. Moreover, according to Java8 in Action p.305 you shouldn’t use them. The justification of use primitive on streams are the performance reasons. In case of huge number of elements, boxing/unboxing overhead is significant. But this is senselessly since there is only one element in Optional. … Read more