** SCJP 5.0 84% **
** SCWCD 1.5 76% **
** SCJP 5.0 84% **
** SCWCD 1.5 76% **
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
** SCJP 5.0 84% **
** SCWCD 1.5 76% **
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Dieter Quickfend wrote:== will work here, the equals method won't, and I'll tell you why:
== checks for identity, meaning it will only return true if the objects compared have the same address in memory
equals() checks for meaningful equivalency, meaning it will return true whenever the equals() method returns true. Those conditions depend on which implementation of equals() the developer of the first class you're comparing has used. There are rules for creating an appropriate equals class, but you don't always have a guarantee that the implemented equals() method is appropriate. Even if it were appropriate, it would probably only check if the contents are equal, which, if your method "getInstance()" say, returns a new instance for every call, would also result in true, which is definitely not what you want.
which means if you want to make sure it is returning the same item, and not an equivalent other instance, you must use ==.
I hope that is sufficient explanation.
Martin Vanyavchich wrote:It depends on programmers opinion, or the innerworks of the program. For example if you mada a person class with all kinds of attributes, from name, height, age, skin tone, eye color, IQ etc. your equals method might take all of them into consideration or just name and surname.
** SCJP 5.0 84% **
** SCWCD 1.5 76% **
You can read the whole thing hereJavaDoc wrote:The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
** SCJP 5.0 84% **
** SCWCD 1.5 76% **
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |