![]() |
![]() |
|
home—info—lects—labs—exams—hws
tutor/PIs—Object120 + its docs—java.lang docs—java.util docs
Review: Non-static methods: - how to *call* them
Song s1 = new Song( "Violet Hill", "Coldplay", 180, true ); // Instead of fitsOnDisk(s1,2.5), write: s1.fitsOnDisk(2.5); |
/* Instead of: static boolean fitsOnDisk(Song thisSong, double freeSpace) { return thisSong.length * MB_PER_SEC <= freeSpace; } We will write: */ |
What's going on: When comparing two object references,== returnstrue if (and only if) they reference (point to) the identically-same object.
(reached here)
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.
home—info—lects—labs—exams—hws
tutor/PIs—Object120 + its docs—java.lang docs—java.util docs
©2010, Ian Barland, Radford University Last modified 2010.Oct.21 (Thu) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |