public abstract class HolidayPackageVariant {
private HolidayPackage holidayPackage;
private String typeHolidayPackage;
@Override
public int hashCode() {
return Objects.hashCode(getTypeHolidayPackage(), getHolidayPackage());
}
}
public final class FlightHolidayPackageVariant extends HolidayPackageVariant{
private Destination originCity;
@Override
public int hashCode() {
// need to add super.hashCode() here somehow ?
return Objects.hashCode(getOriginCity() );
}
}
Google guava hashode(): Objects.hashCode works on member objects. How do I specify super class hashCode() in the derived::hashCode() ? I can directly use super.members in the derived class hashCode() function, but if the super.hashCode() changes in any way, that will not be reflected in the derived:hashCode(…).
Sorry for the non-answer but: this is probably not really what you want to do. Effective Java has a long exploration of why subclassing a value type to add an additional value component is a bad idea. In the second edition, it’s Item 8, “Obey the general contract when overriding equals.” Also see Item 16, “Favor composition over inheritance.”