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

How to specify toString() method on interface? #825

Closed
MartyIX opened this issue Sep 11, 2018 · 3 comments
Closed

How to specify toString() method on interface? #825

MartyIX opened this issue Sep 11, 2018 · 3 comments
Labels

Comments

@MartyIX
Copy link

MartyIX commented Sep 11, 2018

Hi,

Let's say I have the following interface:

// Define abstract value type
@Value.Immutable
public interface ValueObject {
  String name();
  List<Integer> counts();
  Optional<String> description();
}

Can I specify that I don't want counts to be taken into account in generated toString() method?

Best regards,
Martin

PS: I know I can convert the interface to an abstract class, but it collides with some of our custom-made tooling that supposes that immutables are always interfaces.

@datval
Copy link

datval commented Sep 11, 2018

You can add @Value.Redacted annotation to counts() method.
Redacted attributes

@elucash
Copy link
Member

elucash commented Sep 11, 2018

@MartyIX thank you for asking this! @datval 's suggestion is the best way to handle your situation (@Value.Redacted). We're thinking of also adding general capability for interfaces to specify ("underwrite") equals / hashCode / toString as it is possible with abstract classes (maybe defining special static methods in interfaces), but we're not there yet (#739)

@MartyIX
Copy link
Author

MartyIX commented Sep 11, 2018

@datval @elucash Thank you guys!

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

No branches or pull requests

3 participants