How can I cast a Java object into a boolean primitive
I tried like below but it doesn’t work
boolean di = new Boolean(someObject).booleanValue();
The constructor Boolean(Object) is undefined
Please advise.
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.
If the object is actually a
Booleaninstance, then just cast it:The explicit cast will do the conversion to
Boolean, and then there’s the auto-unboxing to the primitive value. Or you can do that explicitly:If
someObjectdoesn’t refer to a Boolean value though, what do you want the code to do?