Make String.format(“%s”, arg) display null-valued arguments differently from “null”

前端 未结 10 1227
忘了有多久
忘了有多久 2021-02-06 21:22

Consider the custom toString() implementation of a bean:

@Override
public String toString() {
    String.format(\"this is %s\", this.someField);
}
<         


        
10条回答
  •  天涯浪人
    2021-02-06 21:50

    You could just do

    String.format("this is %s", (this.someField==null?"DEFAULT":this.someField));
    

提交回复
热议问题