Home > Back-end >  Can .equalsTo() method in Java handle null value?
Can .equalsTo() method in Java handle null value?

Time:12-14

if(dbRecord.getPropertyDocumentTypeDetailID().getTypeDetailID().equalsTo(applicationPropertyDetailBean.getPropertyDocumentTypeDetailID()) !=0){
                    isRequiredRoiCall=true;
                }

This piece of code returns Null exception when one of the values is null.

CodePudding user response:

You can add if statement with null checking.

Smth like this:

if(dbRecord.getPropertyDocumentTypeDetailID() != null && ...)

Or use Optional.ofNullable

CodePudding user response:

You shoud make sure:

dbRecord != null

dbRecord.getPropertyDocumentTypeDetailID() != null

dbRecord.getPropertyDocumentTypeDetailID().getTypeDetailID() != null

applicationPropertyDetailBean != null

  • Related