News for hackers. Stuff that matters.
Re:Java Puzzle: Square Root by raylu on Tuesday March 19, 2013 @11:34PM (#5405466)
equals() isn't being called on your class; it's being called on the result of n.divide()
Re:Java Puzzle: Square Root by web007 on Tuesday March 19, 2013 @11:55PM (#5405536)
I don't know Java, clearly, as I don't even know what to name a file that's going to do the override. Also, as mentioned elsewhere, SecureRandom seems the easier target as it's a pluggable interface for entropy providers.

That said, can't you override the equals() for your subtype? I'm talking about the implementation of BigInteger::equals(MyBigInt x), not MyBigInt::equals(BigInteger x). Or does that need to be done on BigInteger-proper, versus its subclass?

Re:Java Puzzle: Square Root by raylu on Wednesday March 20, 2013 @12:16AM (#5405609)
You can override the .equals() for your subtype but look at the check:

    if (n.divide(root).equals(root)) {
It never calls root.equals(). It calls .equals() on the result of the .divide(), which is a standard java.math.BigInteger.