What is the best coding standard for Java for a bean variable:
1. Should I use primitive data type?
2. Should I use wrapper type?
Or both are same?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends. Both exist for a good reason.
Primitives should be preferred as much as possible. They cost less, and are non-nullable, which avoids quite a lot of potential bugs.
A wrapper can be used to represent a nullable value (for example, in JPA, to represent a nullable column value in a database, or in JAXB, to represent an optional element or attribute of an XML element).