java - Handle != null 检查两个变量

标签 java

<分区>

我有以下代码,我正在检查两个变量的非空检查。

 if (userParameter != null || configurationParameter != null){
   add.userParameter();
   add.configurationParameter();
 }

有什么方法可以在一个if条件下检查null,比如if((userParameter or configurationParameter) != null)在 Java 中。

最佳答案

There is no way to compare null(single) thing with multiple things(i.e. userParameter & configurationParameter) in java.

但是你可以写一个像下面这样的方法,当你用 || 检查多个 null 值时使用它:-

public boolean isNull(Object... args){
for(Object arg: args){
  if(arg==null) return true;
}
return false;
}

关于java - Handle != null 检查两个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41672371/

相关文章:

java - "enter"的 JSP 字符串导致问题

java - 绕轴旋转椭圆

java - 如何立即释放等待 BlockingQueue 的线程

java - FXML 最小高度和最大宽度属性被忽略了吗?

java - 使用 Maven ScmProvider.list 方法时,短划线转换为连字符

java - 使用命令行参数运行 eclipse

java - 如何计算到某个日期的剩余时间

java - 在带有 JFrame 表单的 Netbeans derby 中使用带有 WHERE 子句的 SELECT 语句

java - 选择物理字体和逻辑字体

java - 配置 checkstyle do while 语句样式