views:

298

answers:

1

I don't see anything that I am doing wrong, but NetBeans gives me the following error:

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");
    }
}
+6  A: 

It's spelled instanceof.

Also, as Tom Hawtin mentioned in a comment, if you're using Java 1.5 or later you can write compareTo(Employee emp) to avoid using instanceof at all. There's a thorough section on writing Comparable types in the Object Ordering Java tutorial.

Bill the Lizard
Wouldn't that give a syntax-error?Try a clean-build or restart netbeans.
Pindatjuh
@Pindatjuh: It does give the syntax error "incomparable types..."
Bill the Lizard
you're right. i can't believe i made that mistake
Don't feel bad. I wouldn't have gotten it so fast if I hadn't done it before. :) And as Pindatjuh points out, it's not even the error message you'd expect from that typo.
Bill the Lizard