I'm trying to use ReflectiontoStringBuilder class with special style. The code is copied from an older SO code.
@SuppressWarnings("unused")
public String toStringWithAttributes() {
double noValue = 0.0;
Object myself = this;
ReflectionToStringBuilder builder = new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) {
@Override
protected boolean accept(Field field) {
try {
return super.accept(field) && field.get(myself) != null
} catch (IllegalAccessException e) {
return super.accept(field);
}
}
};
return builder.toString();
}
I'm trying to add more conditions on the value of the objects. Such as && field.get(myself) != 0.0
. How do we handle this in the style definition.
Aucun commentaire:
Enregistrer un commentaire