now for the CompareTo() the implementation must be as follows.
let b1 & b2 are your book instances
1) if b1.equals(b2) is true then b1.compareTo(b2)==0 must be true...
2) if b1.equals(b2) is false then b1.compareTo(b2) must return a non-zero...
3) any_book_obj.compareTo(null) must throw NullPointerException.
4) for incompatiable class it must throw ClassCastException.
thank you ravi
I wanted to sort the Book objects according to the year.Thats why I used compareTo in Book claas.After making year an Integer instead of a primitive the code worked.
Is there any other means of getting it done that is better?(to be used with sort())