일반적으로 type 매개 변수를 지정하지 않고 java.lang.Comparable
인터페이스를 구현 한 것처럼 보입니다.왜 <T> 번을 여러 번 구현할 수 없습니까?
public abstract class Area implements Comparable {
@Override
public int compareTo(Object other) {
if (other instanceof Area)
return new Double(getArea()).compareTo(other.getArea());
return -1; // or something else
}
abstract public double getArea();
}
사과와 사과를 비교하기 때문에 유형을 지정하는 것이 타당합니다.
public abstract class Area implements Comparable<Area>, Comparable<Volume> {
@Override
public int compareTo(Area other) {
// ...
}
@Override
public int compareTo(Volume other) {
// ...
}
}
하지만 자바 컴파일러는 나에게 말한다 :
Area.java:2: error: repeated interface
public abstract class Area implements Comparable<Area>, Comparable<Volume> {
^
Area.java:2: error: Comparable cannot be inherited with different arguments: <Area> and <Volume>
- 내가 함께
Area
을 비교하는 다른 클래스를 소개합니다public abstract class Area implements Comparable<Area> { @Override public int compareTo(Area other) { // ...
는, 나는 다음을 수행 할 수 있다고 생각 제네릭 인터페이스의 형식 인수를 지정하는 데 단점이 있습니까?
- Java가이 다중 구현을 허용하지 않는 이유는 무엇입니까?
참고 : 나는 1.7.0_45
더 나은 질문은 왜 이것이 유익 할 것이라고 생각합니까? 그리고'newYork.compareTo (eleven)'이 사과에게 사과가되는 방법은 무엇입니까? :-) – haraldK