내가 잘못하고 있어요 아무것도 표시되지 않지만, 넷빈즈 나에게 다음과 같은 오류 제공합니다 : 그것은 instanceof
을 철자자바 Comparable 인터페이스 compareTo 메소드
incomparable types
required: boolean
found: java.lang.Object
public int compareTo(Object obj) {
if(obj instaceof Employee){
Employee employee = (Employee) obj;
if(this.weekly_earnings > employee.weekly_earnings)
return 1;
else if(this.weekly_earnings == employee.weekly_earnings)
return 0;
else
return -1;
}
else{
System.out.println("Error");
}
}
instaceof가 존재하지 않습니다. –
그리고 오류 케이스에서 아무것도 반환하지 않습니다 ('ClassCastException'을 던져야하며 실제로는 generics를 사용해야합니다). –
방금 반환했을 경우 (this.weekly_earnings - employee.weekly_earnings), 모든 if 문을 저장하면 더 좋을 것이라고 덧붙이고 싶습니다. – DaveJohnston