Apache9 commented on a change in pull request #673: HBASE-23093 : Avoid 
Optional Anti-Pattern where possible
URL: https://github.com/apache/hbase/pull/673#discussion_r333494335
 
 

 ##########
 File path: 
hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerWrapperImpl.java
 ##########
 @@ -275,7 +276,7 @@ public int getFlushQueueSize() {
 
   @Override
   public long getBlockCacheCount() {
-    return this.blockCache.map(BlockCache::getBlockCount).orElse(0L);
+    return this.blockCache != null ? this.blockCache.getBlockCount() : 0L;
 
 Review comment:
   > Agree @Apache9 However, Optional.map internally does isPresent() check.
   
   isPresent is just like the null check, the intention is to avoid explicit 
isPresent calls. The provided page is about using Optional as parameters, but 
here it is a field, not a parameter, and do not need to do extra Optional.of to 
create it, so I do not get the point why we must unwrap it and explicitly then 
use null check? What is the advantage?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to