TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - Java Coding Standard
Search

Rule:  Design33

This rule is Obsolete
Synopsis:Use equals() to compare object references
Language:Java
Severity Level:1
Category:Design


Description:
Use equals() to compare object references; avoid comparing them with ==. This is because equals() compares object values and == only object references. So if the contents of 2 different objects is equal, == returns false.
class Foo {
  boolean bar(Object a, Object b) {
    return a == b;  // might unexpectedly return false
  }
}