I am using a class i made named Key
.
It has 2 fields:
- address (type MyAddress) that have a GUID (type long)
- id (type long)
This class can have at any given point one of the following:
- address is not null and id==-1
- adresss is null and id > 0
Will it be correct to do the following:
int hashcode(){
if (address==null) return Long.hashCode(id)
else return Long.hashcode(address.guid)
}
Is there any problem that might occur from that? I mainly want to make sure that this is the right way to make a hashcode in this union-like class when only one of the fields is relevant in any given time.