Tag: is a reference type pointer CEP bool judgment habit POI
Null problem:
Java types have underlying variable types, reference types.
Write a picture description here
(1) for the underlying variable type, if uninitialized Java will automatically open up space and assign values. int, byte, short, Long is 0;float, double is 0.0;boolean false.
(2) For reference variable types, Java also automatically assigns values to uninitialized variables, which is null.
(because null refers to an indeterminate object, it applies to reference types and not to underlying variable types.) )
Besides, NullPointerException Anomaly.
A pointer is a reference to an object in Java. For example, string A, which is a pointer.
Null pointer Nullpointer, the contents of the pointer is empty, such as pointer A, if it points to null, is a null pointer.
Null pointer exception nullpointerexception, one pointer is null. The object itself is empty, there is no way to call you, you use the method of the object, it is an imposition. Again, uninitialized variable Java will automatically error. For example, string a=null, you have to use a method, such as A.equals (String x), which produces a null pointer exception.
There are a lot of nullpointerexception problems in the project, a general focus:
(1) An object reference is defined, but no new is used directly. For example, string a = Null,list List = null;
(2) The object that is directly fetched or returned is empty without considering whether it is empty. Use the object directly.
Empty question:
Null values generally refer to an object's parameter value as an empty string, for example, obj.value= ", whereas null generally means an object is empty, that is, obj = null;
If an object is null, it must not take all of its parameter values, and if the object is not empty, the value of one of its arguments may be empty.
Like what
(2) Integer integer
if (id = = NULL) {
throw new Exception ("Argument cannot be empty! ");
Here I used to use "". Quals (ID) to empty, was the team laughed for half a year. Integral type does not require "". equal (ID), integer type is not nullable. The integer type is used in the project, and the integer is the wrapper class that includes the base type int, and NULL when the assignment is not given. The int primitive type initialization is not empty. In both cases, the integer only needs to be judged by the null value.
(3) The list type is not empty
if (Collectionutils.isempty (list)) {
throw new Exception ("parameter exception! Www.kaixinyle.com ");
Source:
public static Boolean IsEmpty (www.thylpt1.com collection<?> Collection) {
Return (collection = = NULL | | collection.isempty ());
}
public boolean isEmpty (www.2018yulpt.com) {
return size () = = 0;
8
(3) Map is not empty
if (Collectionutils.isempty (Existmap)) {
}
if (Existmap.isempty (www.yinfenyule.com)) {
This will also be an error.
}
Java types have underlying variable types, reference types.