Immutables: How to specify toString() method on interface?

Created on 11 Sep 2018  Â·  3Comments  Â·  Source: immutables/immutables

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.

question

All 3 comments

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

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

@datval @elucash Thank you guys!

Was this page helpful?
0 / 5 - 0 ratings