帮忙看看程序,谢谢了
在Comparable.java文件中
package chapter1;
public interface Comparable
{
public abstract int compara(Object obj1,Object obj2);
}
在ItemComparer.java文件中
package chapter1;
public class ItemComparer implements Comparable
{
public int compare(Object obj1, Object obj2)
{
if ((obj1 instanceof Item)&&(obj2 instanceof Item))
{
Item item1 = (Item)obj1;
Item item2 = (Item)obj2;
return item1.ID.compareTo(item2.ID);
}
else
return -1;
}
}
请问错在哪???谢谢了
------解决方案--------------------public interface Comparable
{
public abstract int compara(Object obj1,Object obj2);
}
改成
public interface Comparable
{
int compara(Object obj1,Object obj2);
}
------解决方案--------------------compara--> compare
------解决方案--------------------Item ?是什么?
你的程序里没有
最主要的是
public interface Comparable
{
public abstract int compara(Object obj1,Object obj2);
}
public int compare(Object obj1, Object obj2)
compare 改成 compara
------解决方案--------------------if ((obj1 instanceof Item)&&(obj2 instanceof Item))
Item是什么东东?