CSE 116 Lecture Notes - Lecture 27: Negative Number

33 views4 pages

Document Summary

Provides simple, abstract way to compare data found in java. lang package just like string: makes coding easier by simplifying search & compare. Single method defined by comparable int compareto(e o: compare this instance with o(ther) instance return value unimportant, except for its relative value, sign of result shows ordering of this & o. Only if for all elements a & b either: a < b or a == b or a > b. Clicker question: null legal o in compareto()? public int compareto(nhlteam o) { //code comparing number of wins for this & o class nhlteam implements comparable : yes. null used like any element, no. Should trigger exception: yes. null is smallest element, yes. null is largest element, sort of. Make class comparable only when possible to compare & order with any instance allowed. //need to return zero in this case return 0; //need to return positive number here return 73;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents