When to use primitive and when reference types in Java

后端 未结 11 564
旧时难觅i
旧时难觅i 2020-12-01 02:55

In which case should you use primitive types(int) or reference types (Integer)?

This question sparked my curiosity.

11条回答
  •  感情败类
    2020-12-01 03:23

    When we deal with Spring getRequest mapping methods, using boolean value does not work.

    For instance :

    @GetMapping("/goal")
    public boolean isValidGoal() { 
        boolean isValid = true;
        return isValid;
    }
    

    Always opt for Boolean in those cases.

提交回复
热议问题