|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
What `equals` means: If you don't do anything to say otherwise, your own classes have aequals (inherited fromjava.lang.Object ) which just does the same thing== does (?!):If you want
// Inside class java.lang.Object, deep in the bowels of Java: public boolean equals(Object that) { return this == that; }equals to do something smarter, you have to write it yourself (“overriding the version inherited fromObject ”). That's whatclass String does, which is whyequals works forString s.
We will draw pictures for the following:
int n = 7; int k = n; Song s1 = new Song(...); Song s2 = s1; Song s3 = new Song(...); assigning( n, s2 ); |
static void assigning( int z, Song lalala ) { lalala.artist = "Justin Bieber"; // I am *not* assigning to a local variable! Others referring to object can see changes. z = z+1; // assigning to my local variable -- nobody else can see changes. lalala = new Song(...) // assigning to my local variable -- nobody else can see changes. } |
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
©2012, Ian Barland, Radford University Last modified 2012.Oct.17 (Wed) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |