嗨,我是编程的新手,我的比较方法有困难,我有几个类,我的初始问题是我的父类.
我收到此错误:
Person不是抽象的,并且不会覆盖Comparator中的方法比较(java.lang.Object,java.lang.Object)
public class Person implements Comparator
{
//some methods
public int compare(Person p1, Person p2)
{
// if last names are the same compare first names
if(p1.getLastName().equals(p2.getLastName()))
{
return p1.getFirstName().compareTo(p2.getFirstName());
}
return p1.getLastName().compareTo(p2.getLastName());
}
Run Code Online (Sandbox Code Playgroud)
我的孩子班看起来像这样:
public class Player extends Person implements Comparator
{
//some methods
public int compare(Player p1, Player p2)
{
if(p1.getGamesPlayed()<p2.getGamesPlayed())
{
return -1;
}else if (p1.getGamesPlayed()==p2.getGamesPlayed())
{
return 0;
}else
{
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
我还有一个俱乐部类,它将所有信息存储在ArrayList <Player>团队中.
我的界面:
public interface Comparator<T>
{
int compare(T …Run Code Online (Sandbox Code Playgroud)