Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.java.lang.oop.lesson4.comparable;
- public class Item implements Comparable {
- private Integer size;
- public Item(int size) {
- this.size = size;
- }
- public Integer getSize() {
- return size;
- }
- public void setSize(int size) {
- this.size = size;
- }
- public int compareTo(Object o) {
- if (o == null) {
- return -1;
- }
- Item anotherItem = (Item) o;
- return this.getSize().compareTo(anotherItem.getSize());
- }
- @Override
- public String toString() {
- return "Item{" +
- "size=" + size +
- '}';
- }
- }
Add Comment
Please, Sign In to add comment