有没有办法屏蔽 Java Records 中自动生成的“toString()”方法上的敏感字段而不覆盖它? (即注释)
即
public record SomeRecord(..., String apiKey, String password, ...) { }
请不要“使用龙目岛!”答案:)
我认为你可以通过对象包装敏感信息:
record SensitiveInfo(String info) {
public String toString() {
// add your masking func here
}
// other necessary methods to use with info field
}
所以在你的 SomeRecord 中:
record SomeRecord(..., SensitiveInfo apiKey, SensitiveInfo password)