In my code there are a lot of final values, like 10000. They never change, i do nothing with them, just sometimes checks like if(number1 == number2).
Is it better to use int or Integer for such numbers?
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.
In your case, use
int.In a general case, if you’re in the situation where you could feasibly use either the primitive value is almost always preferred:
Integertype – you’d have to use.equals()to ensure you were getting what you wanted. See here for more details.Memory requirements are a lot less of an issue these days, but the big gotcha is the second one, which can cause the potential for a lot of bugs if you’re not aware of it (especially since there’s cases where
==will work as you expect, and others where it won’t – it’s not a “reliable” bug in that sense.)