I have the below method call. If name
or desc
is null, it uses the word null. Instead I would like an empty string.
How to achieve this as part of the method call itself. I don't want to do this outside of the method call with if conditions.
boolean creatok = users.create (String.valueOf(name), String.valueOf(desc));
boolean creatok = users.create (Objects.toString(name, ""), Objects.toString(desc, ""));
我认为您应该使用条件,如果要避免使用'if'子句,请使用三元运算符
boolean creatok = users.create(name == null? "" : String.valueOf(name), name == null? "" : String.valueOf(name));
如果你不想写,你可以做这样的事情
boolean creatok = users.create (name == null ? "" : name, desc == null ? "" : desc);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.