Collections.max() 不正确的参数
我只是想找到“官员”列表的最大值。我正在处理的任务的规格不允许我对军官进行比较,因此我使用比较器来比较它们。
然而,编译器抱怨我的参数类型。谁能看出出了什么问题吗? (不用担心返回...我还没有这样做。)
在下面的片段之外,军官是列表<军官>;已初始化。
Collections.max(officers, new Comparator<Officer>()
{
public int compare( Officer a, Officer b )
{
return -1; //will do after
}
}
);
任何建议将不胜感激!
I'm simply trying to find the max of a list of "Officers". The specs of the assignment I'm working on don't allow me to make the Officers comparable, so instead I'm using a Comparator to compare them.
However, the compiler is complaining about the types of my arguments. Can anyone see what's wrong? (Don't worry about the return... I haven't done that yet.)
Outside of the fragment below, officers is a List<Officer> which has been initialized.
Collections.max(officers, new Comparator<Officer>()
{
public int compare( Officer a, Officer b )
{
return -1; //will do after
}
}
);
Any suggestions would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这编译得很好。这是 ideone.com 演示
因此,您发布的代码没有任何问题。一定是其他什么地方出了问题。
This compiles just fine. Here's an ideone.com demo
So, nothing wrong with the code you posted. Must be something else that's wrong.