Javaの質問があります。クラスにComparableを実装しようとしています。私の調査に基づくと、私のクラスのステートメントは次のようになります。
public class ProEItem implements Comparable<ProEItem> {
private String name;
private String description;
private String material;
private int bomQty;
// other fields, constructors, getters, & setters redacted
public int compareTo(ProEItem other) {
return this.getName().compareTo(other.getName());
}
}// end class ProEItem
ただし、クラス宣言のComparableの後に{が予期されるコンパイルエラーが発生します。これは、Java 1.4.2に固執しているためだと思います(そうです、悲しいことにそうです)。
だから私はこれを試しました:
public class ProEItem implements Comparable {
private String name;
private String description;
private String material;
private int bomQty;
// other fields, constructors, getters, & setters redacted
public int compareTo(ProEItem other) {
return this.getName().compareTo(other.getName());
}
}// end class ProEItem
比較可能な後にProEItemがない場合、しかし私のコンパイルエラーはこれです:
"ProEItem is not abstract and does not override abstract method compareTo(java.lang.Object) in java.lang.Comparable
public class ProEItem implements Comparable {"
だから私の質問は、1.4.2で同等のものを実装するために私が間違っていることは何ですか?ありがとうございました。