Java 什么事!在这个代码中输入什么意思?

Java 什么事!在这个代码中输入什么意思?,java,operators,Java,Operators,什么是!在下面的代码段中键入mean?为什么要放 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("motorc

什么是
!在下面的代码段中键入
mean?为什么要放

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>");
}
String type=request.getParameter(“tipo”);
if(type==null){
out.print(“错误:未选择字段类型
”; } 如果(!type.equals(“自动”) &&!type.equals(“拖车”) &&!type.equals(“摩托车”)){ 打印输出(“错误:字段错误(“+类型+”)
”; }

有人能给我解释一下这些代码吗!键入

“!”是一个布尔运算符,它只是表示不(求反)


所以!如果type不是“auto”,type.equals(“auto”)将计算为true。type是
String
对象的一个实例,它的方法是
String等于(…)
,该方法返回一个
布尔值

”这是求反运算器,可反转任何布尔值

所以
!type.equals(“auto”)
是一个
布尔值
条件,用于比较字符串变量与名称类型是否具有值“auto”。

!不是,并且equals()方法返回布尔值,这意味着它返回true和false,然后!将否定它,它使真、假和假为真,例如:

String text = "test";

Text.equals("test") returns true
And !text.equals("test") returns false

Text.equals("example") returns false
And !text.equals("test") returns true
或者只是在代码中,它意味着检查文本是否不等于…

不等于…。它不是
(!type).等于(“auto”)
,它是
!(键入.equals(“auto”)
即首先计算
.equals
零件,然后计算
应用于该结果。