Best way to override toString method for “Sensitive” classes

Let’s say I have a bunch of value classes that contain PII data.

value class Name(value: String) value class Email(value: String) value class PhoneNumber(value: String) 

I want to make sure I don’t accidentally log the PII to console. Of course I can just override the toString method of each class, but is there a more elegant way that doesn’t involve so much code duplication? It would be nice if I could just define a Sensitive interface, put the logic in there, and have the value classes implement it.

submitted by /u/iamiamwhoami
[link] [comments]