In a drive to improve performance, the bitcoinj library defines the class LazyECPoint whose instances are ECPoint which may not have yet been initialized. Hence because an ECPoint (say point) is essentially the same thing as its lazy counterpart (say lazy), the library feels a call to lazy.equals(point) should return true. However, a call to point.equals(lazy) still returns false, and in fact, if point is viewed as an Object same = point, then lazy.equals(same) is now false. My personal gut feeling is that the library should not be the way it is. I was wondering if a professional developer would care to comment as to what the proper way to deal with this situation is. Is it worth attempting to compare ECPoint's and LazyECPoint's, and if so is it worth adding the complexity to the code so as to remove the sort of quirks I have mentioned? (In fact, ECPoint is not a bitcoinj class, it is part of the crypto library spongycastle so I can't even see how to set things straight, without changing spongycastle's code). I attach a code snippet:

import org.bitcoinj.core.ECKey;
import org.bitcoinj.crypto.LazyECPoint;
import org.spongycastle.math.ec.ECPoint;

public class Test {
  public static void main(String[] args){

    ECKey key = new ECKey();                    // some random (compressed) key
    ECPoint point = key.getPubKeyPoint();       // associated ECPoint
    LazyECPoint lazy = new LazyECPoint(point);  // same, but different type

    System.out.println(lazy.equals(point));     // true 
    System.out.println(point.equals(lazy));     // false, equality not symmetric

    Object same = point;
    System.out.println(lazy.equals(same));     // false ...


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.