튜토리얼을 읽었지만 Country
클래스 Comparable
을 내 BST
으로 만들지 못했습니다.자신의 클래스를 'Comparable'로 만들기
홈페이지 :
BinarySearchTree A = new BinarySearchTree();
Country a = new Country("Romania", "Bucharest", 1112);
A.insert(a);
나라 클래스 :
public int compareTo(Object anotherCountry) throws ClassCastException {
if (!(anotherCountry instanceof Country))
throw new ClassCastException("A Country object expected.");
String anotherCountryName = ((Country) anotherCountry).getName();
int i = this.name.compareTo(anotherCountryName);
if(i < 0){
return -1;
} else {
return 0;
}
}
오류 :
@Override
public int compareTo(Object anotherCountry) throws ClassCastException {
if (!(anotherCountry instanceof Country))
throw new ClassCastException("A Country object expected.");
String anotherCountryName = ((Country) anotherCountry).getName();
return this.name.compareTo(anotherCountryName);
Description Resource Path Location Type
이름 충돌 : 타입 나라의 방법은 compareTo (개체)은 compareTo와 같은 삭제가 있습니다 (T) Comparable 유형이지만 재정의하지 않습니다. Country.java/Lab2_prob 4/src 행 17 Java 문제
Description Resource Path Location Type
The method compareTo(Object) of type Country must override or implement a supertype method Country.java /Lab2_prob 4/src line 17 Java Problem
및 클래스 :
public class Country implements Comparable<Country>{
private String name;
private String capital;
private int area;
Description Resource Path Location Type
상속 된 추상 메소드 Comparable.compareTo (국가) Country.java/Lab2_prob 4/src에 라인이 자바 문제
'Country' 클래스가'Comparable'을 확장합니까? –
실제로 어떤 문제 또는 오류가 발생합니까? – DNA
죄송합니다. 오류가 추가되었습니다. –