You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Duo Zhang (Jira)" <ji...@apache.org> on 2019/09/29 10:30:00 UTC
[jira] [Commented] (HBASE-23093) Avoid Optional Anti-Patterns
[ https://issues.apache.org/jira/browse/HBASE-23093?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16940339#comment-16940339 ]
Duo Zhang commented on HBASE-23093:
-----------------------------------
I agree that Optional should not be used as parameter as it causes unecessary wraping/unwraping, and we could introduce methods with the same name but different parameters to avoid passing null.
But for using as a field, it is a good sign that the field can be null. And sometimes we want to get the field and will return a Optional, if we do not use Optional field, then we need to call Optional.ofNullable everytime...
> Avoid Optional Anti-Patterns
> ----------------------------
>
> Key: HBASE-23093
> URL: https://issues.apache.org/jira/browse/HBASE-23093
> Project: HBase
> Issue Type: Improvement
> Affects Versions: 3.0.0, 2.3.0, 1.6.0
> Reporter: Viraj Jasani
> Assignee: Viraj Jasani
> Priority: Minor
>
> Optional should be used as a return type only. It's a neat solution for handling data that might not be present. We should avoid using Optional Anti-Patterns i.e. using it as a field or parameter type due to these reasons:
> 1. Using Optional parameters causing conditional logic inside the methods is not productive.
> 2. Packing an argument in an Optional is suboptimal for the compiler and does an unnecessary wrapping.
> 3. Optional field is not serializable.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)