Tag: 前提条件

空检查错误消息为“为空”或“为空”

在Java代码中执行空检查,并且为空值抛出IllegalArgumentExceptions时,您使用什么类型的消息模板? 我们倾向于使用这样的东西 public User getUser(String username){ if (username == null){ throw new IllegalArgumentException(“username is null”); } // … } 更好的是:“为空”或“为空”,为什么? 对我来说,“无效”感觉更自然。