You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Value.Immutable
public interface Key() {
String key()
}
Then at some point in the future, I add a field to the key:
@Value.Immutable
public interface Key() {
String key()
Optional<String> optionalKey()
}
But, say I was intent on keeping backwards compatibility with the existing keys in the map. Since the new field is an Optional, how could I do this? By default, the hashCode for the new field is factored into Key.hashCode() even if the optionalKey().hashCode() == 0 due to the left shift.
In essence, I would want the optionalKey() to be auxiliary if it was absent and non-auxiliary if the value is present.
The text was updated successfully, but these errors were encountered:
Say I had an object that I use as a key in map:
Then at some point in the future, I add a field to the key:
But, say I was intent on keeping backwards compatibility with the existing keys in the map. Since the new field is an Optional, how could I do this? By default, the hashCode for the new field is factored into
Key.hashCode()
even if theoptionalKey().hashCode() == 0
due to the left shift.In essence, I would want the
optionalKey()
to be auxiliary if it was absent and non-auxiliary if the value is present.The text was updated successfully, but these errors were encountered: