I have the following code fragment
System.out.printf("%b\n", 123);
which prints “true”.
Can somebody explain this behavior? shouldn’t this throw a IllegalFormatException?
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.
Well since the specification says:
“If the argument arg is null, then the result is “false”. If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(). Otherwise, the result is “true”. ” (src)
The behavior is quite expected isn’t it? Why they decided to implement it that way – no idea, I’d agree that it’s not intuitive (but well it follows C which also prints just anything if you give it the wrong arguments 😉 )