Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auxiliary for Optional.absent() #1116

Open
jeremyjliu opened this issue Oct 31, 2019 · 0 comments
Open

Auxiliary for Optional.absent() #1116

jeremyjliu opened this issue Oct 31, 2019 · 0 comments

Comments

@jeremyjliu
Copy link

Say I had an object that I use as a key in map:

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant