Should Java 8 getters return optional type?

后端 未结 5 1182
自闭症患者
自闭症患者 2020-11-22 05:42

Optional type introduced in Java 8 is a new thing for many developers.

Is a getter method returning Optional type in place of th

5条回答
  •  遇见更好的自我
    2020-11-22 06:19

    I'd say in general its a good idea to use the optional type for return values that can be nullable. However, w.r.t. to frameworks I assume that replacing classical getters with optional types will cause a lot of trouble when working with frameworks (e.g., Hibernate) that rely on coding conventions for getters and setters.

提交回复
热议问题