First of all, you wrote the if conditional statement if(a=1){} wrong. It should be written as if(a==1){} Secondly, if the reference type a of String is empty, if the method of a is called Will throw the null pointer
String a=null;
if (a.equals("")) {
System.out.println(1);
}
If you write like this, you must determine that a is not null. If you don’t want to write the operation of determining that a is not null, you can write it as
What is written in the brackets of the if statement is a judgment expression, the result is true or false, and the a=1 you wrote is an assignment expression
First of all, you wrote the if conditional statement if(a=1){} wrong. It should be written as if(a==1){}
Secondly, if the reference type a of String is empty, if the method of a is called Will throw the null pointer
If you write like this, you must determine that a is not null. If you don’t want to write the operation of determining that a is not null, you can write it as
What is the syntax of
a=1
If a is String type;
a= "1";
If a is int type;
a = 1;
If a is int type, int type does not have null
null can only Judge String
What is written in the brackets of the if statement is a judgment expression, the result is true or false, and the a=1 you wrote is an assignment expression
The type in the brackets is bool, yours is an assignment