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
为空,我将得到一个异常,例如,如果resultIsRight
没有建议。
答案 0 :(得分:2)
在Java中,有两种不同类型的数据类型:Primitives和References。
布尔值是基元,不能以任何方式为空。无论是真还是假,但永远不会为空。
字符串是引用类型,引用可以为null。
在此处阅读有关基元的更多信息:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html