I have got this code, and I get an error incomparable types: java.lang.String and int, for this line of code
if ((this.name.String.compareTo(obj.name == 0)) && (this.age = obj.age))
The method is this:
public int compareTo(Object o)
{
int result;
AnyClass obj = (AnyClass)o;
if ((this.name.String.compareTo(obj.name == 0)) && (this.age = obj.age))
{
result = 0;
}
else if (this.name.compareTo(obj.name) > 0)
{
result = 1;
}
else
{
result = -1;
}
return result;
}
I think that position of your bracket isn't correct,
this.name.String.compareTo(obj.name == 0))
obj.name == 0 is the place where you probably compare String (name) to int (0). I guess you wanted to use compareTo on obj.name and then check if it's equal to zero.
I also think that in the second part
(this.age = obj.age)
You wanted to use == instead of =, so I think that the code you wanted to use is:
((this.name.compareTo(obj.name)==0) && (this.age == obj.age))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With