Home > Blockchain >  Checkstyle's SimplifyBooleanExpressionCheck
Checkstyle's SimplifyBooleanExpressionCheck

Time:07-22

I have an expression like

MyRequest request = someObject.getRequest();
boolean isInitialRequest = initialRequest == null ? true : false;

Unfortunately checkstyle does not like that. How can I simplify this to satisfy checkstyle?

CodePudding user response:

You don't need to add ? true : false. The condition initialRequest == null already returns true or false.

This is the same but in a shorter version:

MyRequest request = someObject.getRequest();
boolean isInitialRequest = initialRequest == null;
  • Related