Which is the better practice between Boolean.valueOf() and Java 1.5 autoboxing to create Boolean from booleans and why ?
Which is the better practice between Boolean.valueOf() and Java 1.5 autoboxing to create Boolean
Share
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.
Autoboxing of
booleanis transparently translated toBoolean.valueOf()by the compiler:is translated to:
Use whichever you find more useful and readable. Since using
Boolean.valueOf()is not giving you anything except extra typing, you should aim for autoboxing.Situation complicates when you think about opposite conversion – from
Booleantoboolean. This timeBoolean.booleanValue()is called transparently for you by the compiler, which can theoretically causeNullPointerException.