Optional in Lombok

后端 未结 1 1666
慢半拍i
慢半拍i 2020-12-30 19:09

I have a class called Address which looks like this:

@Value
class Address {

   @NotNull String userId;
   @NotNull String line1;
   String line         


        
相关标签:
1条回答
  • 2020-12-30 19:33

    The answer is no, and it probably never will.

    You're probably doing it wrong :-) Optional is not a replacement for null nor a fancy way to prevent NullPointerException. It is to indicate that the question is unanswerable, like: what is the average age of an empty list of persons.

    Optionals should never be passed on, but unboxed by the calling code as soon as possible.

    See also https://www.voxxed.com/blog/2015/01/embracing-void-6-refined-tricks-dealing-nulls-java/

    Since these scenarios are just a handful, and Lombok likes to enable programmers to write better code, I don't expect there will ever be support for it in Lombok.

    Disclosure: I am a Lombok developer.

    0 讨论(0)
提交回复
热议问题