2006/7/27, Denis Kishenko <[EMAIL PROTECTED]>:
2006/7/26, Alex Blewitt <[EMAIL PROTECTED]>:
> There are other approaches that could be used instead of this. For
> example, the value of the hashCode could be cached in a private
> variable and then invalidated when any setValue() methods are called.
> One could even imagine a superclass performing this caching work:
>
> public abstract class HashCode {
>  private boolean valid = false;
>  private int hash;
>  public final int hashCode() {
>    if (!valid) {
>      hash = recalculateHashCode();
>      valid = true;
>    }
>    return hash;
>  }
>  protected abstract int recalculateHash();
>  protected void invalidate() { valid = false; }
> }
>
> Of course, you could use the HashCode object to calculate the hash value :-)
Unfortunately
1. class can has temporary private fields (see BasicStroke.java)
We can mark such fields as transient. As for serialization.

2. class can has final fields which take part in hash code calculation
(see EllipticCurve.java)
It's probably the reason to add final fields to hash code calculation.

SY, Alexey

--
Alexey A. Petrenko
Intel Middleware Products Division

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to