Comparing Character, Integer and similar types in Java: Use equals or ==?
问题 I wanted to make sure about something in Java: If I have a Character or an Integer or a Long and those sort of things, should I use equals or is == sufficient? I know that with strings there are no guarantees that there is only one instance of each unique string, but I'm not sure about other boxed types. My intuition is to use equals, but I want to make sure I'm not wasting performance. 回答1: EDIT: The spec makes some guarantees for boxing conversions. From section 5.1.7: If the value p being