2

I am writing a BigInteger Class to work with Big Numbers. My BigInteger class has a String variable number to save the absolute value of the number and an integer variable sign to save the sign of this number.

Here is my function to compare 2 numbers:

public boolean equals(Object other) { if (other instanceof BigInteger) return toString().equals(other.toString()) && sign == other.sign; return false; } 

However, when I compile, I get this error:

java: cannot find symbol symbol: variable sign location: variable other of type java.lang.Object

Can anyone fix this error? Thank you

3
  • Your buildpath is wrong, How do you compile this ? Through eclipse ? Commented Sep 28, 2015 at 10:28
  • Can you post full class. So that only we can resolve Commented Sep 28, 2015 at 10:28
  • Please show the complete class Commented Sep 28, 2015 at 10:29

1 Answer 1

4

You need to cast other to BigInteger.

If you don't cast other it is considered of type Object that hasn't a property sign (exactly the error you had).

Here is the code:

public boolean equals(Object other) { if (other instanceof BigInteger) { return toString().equals(other.toString()) && sign == ((BigInteger) other).sign; } return false; } 
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, it is really my problem
If you find this answer useful you can flag it as the right answer with the green check.
Yeah, I have to wait 10 minutes until I can do that :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.