public static List<String> arithmeticProblemToList(**String arithmeticProblem**, boolean resultIsRight,
double rightResult,
List<String> previousArithmeticProblemsList) throws Exception {
Check.checkNotNull(arithmeticProblem);
Check.checkNotNull(resultIsRight);
if (resultIsRight)
previousArithmeticProblemsList.add(arithmeticProblem + "\t\tRICHTIG");
else {
previousArithmeticProblemsList.add(arithmeticProblem + "\t\tFALSCH " + rightResult + " wäre richtig");
}
return previousArithmeticProblemsList;
}
public static <T> void checkNotNull(T object) throws IllegalArgumentException {
if (object == null) {
throw new IllegalArgumentException("Der Parameter darf nicht null sein.");
}
}
为什么 IntelliJ 给我一个建议,如果字符串 arithmeticProblem
为 null,我将得到一个异常,例如,如果 resultIsRight
则没有建议。
最佳答案
在 Java 中,有两种不同类型的数据类型:基元和引用。
boolean 值是一种原语,无论如何都不能为空。它要么为真,要么为假,但决不为空。
然而,字符串是引用类型,引用可以为空。
在此处了解有关原语的更多信息:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
关于java - 为什么 IntelliJ IDEA 给出异常建议?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44574827/