我有一个考试,这是在模拟中,我不太确定如何去做,这不是家庭作业,它只是试图了解如何去做。谢谢。
public class Book{
private final String title;
private final String author;
private final int edition;
private Book(String title, String author, int edition)
{
this.title = title;
this.author = author;
this.edition = edition;
}
public String getTitle()
{
return title;
}
public String getAuthor()
{
return author;
}
public String getEdition()
{
return edition;
}
}
我需要为上述代码提供 equals、hashCode 和 compareTo 方法的实现。
我不知道该怎么做,compareTo 方法是否与此类似?
title.compareTo(title);
author.compareTo(author);
edition.compareTo(edition);
谢谢,任何帮助将不胜感激。