Just to build upon the answer from @NickNgn, could even make SensitiveInfo a generic class for other data types as well. Something like this:
record SensitiveInfo<T>(T value) {
@Override
public String toString() {
return "SensitiveInfo{" +
"value=*****" +
"}";
}
}
Then could use for different types like this:
record SomeRecord(..., SensitiveInfo<byte[]> byteField, SensitiveInfo<String> stringField)