Home > Blockchain >  Should I use boolean or Boolean in a Spring Boot RestController?
Should I use boolean or Boolean in a Spring Boot RestController?

Time:09-08

Make it any difference to use in the following snippet boolean filterMode or Boolean filterMode? Are they any best practice ? Or its completley irrelevant?

@GetMapping
public NOTMATTER getResultByBoolean(
 @RequestParam(value = "filterMode", required = false) boolean filterMode) {

  //.....
    return List.of("true", "false");
}

CodePudding user response:

Yes it will matter. As you have specified the parameter to be optional, if it is not supplied then default values will be different

// Boolean - default value is null
// boolean - default value is false

CodePudding user response:

There is a difference between the type boolean and the type Boolean.

  • boolean is a primitive type that can accept the values true or false
  • Boolean is an Object that wraps the value of a boolean primitive. It exposes more actions that can be performed on the type.

I suggest you read more about it in the documentation.

The usage depends on your use case.

  • Related