【发布时间】:2016-03-19 10:54:17
【问题描述】:
!type 在下面的 sn-p 中是什么意思?为什么放!?
String type = request.getParameter("tipo");
if (type == null) {
out.print("ERROR: The field type wasn't selected<br>");
}
if (!type.equals("auto")
&& !type.equals("trailer")
&& !type.equals("motorcycle")) {
out.print("ERROR: field error ("+type+")<br>");
}
有人可以向我解释一下这些代码吗,尤其是!type?
【问题讨论】:
-
不是
(!type).equals("auto"),而是!(type.equals("auto")),即首先评估.equals部分,然后将!应用于其结果。