Lombok toString() 输出可以包含换行符吗?
Can Lombok toString() output include newlines?
我希望 Lombok 的 toString() 输出将每个值放在自己的行上。像这样启用它会很棒:
@ToString(includeNewLines = true)
public class MyClass {
...
}
有可能吗?
目前没有直接 @ToString
对您问题中描述的输出格式的注释支持。事实上,Lombok
@ToString
文档ref 包含以下免责声明:
We don't promise to keep the output of the generated toString() methods the same between lombok versions. You should never design your API so that other code is forced to parse your toString() output anyway!
您可以使用:@ToString(onlyExplicitlyIncluded = true)
抑制正常的 toString
字段处理以及 @ToString.Include
调用不带参数的实例(非静态)方法来实现自定义格式设置,但这几乎违背了整个目的。
如果自定义 toString
输出格式对您很重要,Apache Commons Langref org.apache.commons.lang3.builder
package, which provides output format control using the ToStringBuilder
api and ToStringStyle
api 类 中提供了更好的选项。
我希望 Lombok 的 toString() 输出将每个值放在自己的行上。像这样启用它会很棒:
@ToString(includeNewLines = true)
public class MyClass {
...
}
有可能吗?
目前没有直接 @ToString
对您问题中描述的输出格式的注释支持。事实上,Lombok
@ToString
文档ref 包含以下免责声明:
We don't promise to keep the output of the generated toString() methods the same between lombok versions. You should never design your API so that other code is forced to parse your toString() output anyway!
您可以使用:@ToString(onlyExplicitlyIncluded = true)
抑制正常的 toString
字段处理以及 @ToString.Include
调用不带参数的实例(非静态)方法来实现自定义格式设置,但这几乎违背了整个目的。
如果自定义 toString
输出格式对您很重要,Apache Commons Langref org.apache.commons.lang3.builder
package, which provides output format control using the ToStringBuilder
api and ToStringStyle
api 类 中提供了更好的选项。