我陷入了这种困境。我无法弄清楚我在做什么错。任何帮助,将不胜感激。在Collections中遇到案例3、4和5的错误。排序。
Collections类型的sort(List,Comparator)方法不适用于参数(Lead [],Sort.SortByName)
Pages.java
case 0:
mainMenu(leadArray);
menuSelect = -1;
break;
case 1:
newLead( leadArray );
menuSelect = -1;
break;
case 2:
System.out.println( "\nEnter Lead ID: ");
leadSelect = input.nextInt();
viewLead( leadSelect, leadArray );
menuSelect = -1;
break;
case 3:
Collections.sort(leadArray,new Sort.SortByName());
menuSelect = -1;
break;
case 4:
Collections.sort(leadArray,new Sort.SortByStatus());
menuSelect = -1;
break;
case 5:
Collections.sort(leadArray,new Sort.SortByRating());
menuSelect = -1;
break;
default:
System.out.println( "Invalid menu selection!\nPlease try again.");
} // end switch menuSelectr code here
Sort.java
public class Sort {
class SortByName implements Comparator<Lead>
{
@Override
public int compare(Lead a, Lead b)
{
return a.getName().compareTo(b.getName());
} // end compare name
} // end SortByName
class SortByStatus implements Comparator<Lead>
{
@Override
public int compare(Lead a, Lead b)
{
return a.getStatus().compareTo(b.getStatus());
} // end compare status
} // end SortByStatus
class SortByRating implements Comparator<Lead>
{
@Override
public int compare(Lead a, Lead b)
{
return a.getRating() - b.getRating();
} // end compare rating
} // end SortbyRating
}