#769 Small patch for ItemPointer

Editor (491)

Even for such a small wrapper Java developers usually prefer to keep fields private and implement getters and setters if they are needed. In this case it can be enough to make all fields final to make sure that this will be immutable object.

Also the hashCode is not optimal - all pointers to the same file will return same number. While this is unlikely to cause user visible problems it can slow down various operation using this objects.

BTW: I do not see any usage of public ItemPointer(Object file2, Location location, Location location2, Definition definition, String zipFilePath). Is it used in pydev_ext?


  • Fabio Zadrozny

    Fabio Zadrozny - 2008-08-16
    • status: open --> closed-fixed
  • Fabio Zadrozny

    Fabio Zadrozny - 2008-08-16

    Logged In: YES
    Originator: NO

    Hi Rabim,

    Yes, that one with the definition is used in pydev_ext.

    In this case, as equals and hashcode are implemented, making it immutable makes sense... (just applied the patch and make hashCode better).

    As for the getters and setters -- and even being a java programmer for a long time -- I don't usually find real use for them (I know the reason is not to break code if it someday becomes a calculated property -- because java has no support for properties -- but in real life, I find that this happens so rarely that it's not worth the trouble, so, in Pydev getters and setters are not encouraged unless it's really needed -- or if some interface defines it -- which in my view is also a shortcoming of java: not allowing an interface to specify non final attributes).

    And if later that's really needed, a refactoring should suffice.