It depends what you mean by "correct". Assuming that you're using the hashCode() of all the relevant equals()-defining fields, then yes, it's "correct". However, such formulas probably will not have a good distribution, and therefore would likely cause more collisions than otherwise, which will have a detrimental effect on performance.
Here's a quote from Effective Java 2nd Edition, Item 9: Always override hashCode when you override equals
While the recipe in this item yields reasonably good hash functions, it does not yield state-of-the-art hash functions, nor do Java platform libraries provide such hash functions as of release 1.6. Writing such hash functions is a research topic, best left to mathematicians and computer scientists. [...Nonetheless,] the techniques described in this item should be adequate for most applications.
It may not require a lot of mathematical power to evaluate how good your proposed hash function is, but why even bother? Why not just follow something that has been anecdotally proven to be adequate in practice?
Josh Bloch's recipe
- Store some constant nonzero value, say 17, in an intvariable calledresult.
- Compute an inthashcodecfor each field:
- If the field is a boolean, compute(f ? 1 : 0)
- If the field is a byte, char, short, int, compute(int) f
- If the field is a long, compute(int) (f ^ (f >>> 32))
- If the field is a float, computeFloat.floatToIntBits(f)
- If the field is a double, computeDouble.doubleToLongBits(f), then hash the resultinglongas in above.
- If the field is an object reference and this class's equalsmethod compares the field by recursively invokingequals, recursively invokehashCodeon the field. If the value of the field isnull, return 0.
- If the field is an array, treat it as if each element is a separate field. If every element in an array field is significant, you can use one of the Arrays.hashCodemethods added in release 1.5.
 
- Combine the hashcode cintoresultas follows:result = 31 * result + c;
Now, of course that recipe is rather complicated, but luckily, you don't have to reimplement it every time, thanks to java.util.Arrays.hashCode(Object[]) (and com.google.common.base.Objects provides a convenient vararg variant).
@Override public int hashCode() {
    return Arrays.hashCode(new Object[] {
           myInt,    //auto-boxed
           myDouble, //auto-boxed
           myRandomClass,
    });
}
See also
- Object.hashCode()- 
- It is not required that if two objects are unequal according to the - equals(java.lang.Object)method, then calling the- hashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.