I read (and am currently using this) that I can use a long whenever I need an unsigned int. This is working fine for me, but feels like a poor design. Is there a better, more accepted, way to do it? What about unsigned longs?
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.
Since the only unsigned primitive type in Java is
char, which has a very specific meaning to denote a unicode character, usinglongis the most idiomatic way to go.By default, JAXB maps
xsd:unsignedInttolong, too. (source)Edit: If you know the top bit to be 0, or only use operations where the sign doesn’t matter (for instance, you’re just passing data through),
intis probably more common. JAXB only defaults tolongbecause it can’t know how you intend to use the data.