Lombok getter/setter vs Java 14 record

前端 未结 5 1730
梦毁少年i
梦毁少年i 2020-12-16 11:03

I love project Lombok but in these days I\'m reading and trying some of the new features of java 14.

Inside the new capability, there is the record keyword that allo

5条回答
  •  一整个雨季
    2020-12-16 11:23

    I've been playing around with this combination for some time as well and with the slight bit of hands-on I could list down the following differences:

    Lombok

    • Records are not yet a released feature and are just a preview feature. So staying with Lombok makes more sense.
    • They are not yet as powerful a tool to eliminate Lombok all together. Note that the library has much more to offer than just the @Getter, @AllArgsConstructor, @ToString, @EqualsAndHashCode.
    • Experienced by self, the EqualsAndHashCode is not the same as you would expect when it comes to migrating to records.

    Records

    • On a different note, if the requirement of your object representation is to be a "data carrier" you can still seek advantage of Records, without relying on an additional library to reduce the boilerplate code to perform that precisely. That is the reason that as a conclusive note this blog reads the following:

      It will also help teams eliminate many hand-coded implementations of the underlying pattern and reduce or remove the need for libraries like Lombok.

    Of course, on a day-to-day basis, it is always wise based on the requirements of a project to choose which way to follow and practice.

提交回复
热议问题