Preconditions is a class library in Guava, which is used to check the passing parameters. A common usage method is as follows:
Boolean Findelement (list <string> Elements, String Desiredelement) {CheckNotnull (Elements); // ...}
The usage is simple and clear, that is, check whether the parameter Elements is null. If it is null, throw NullpoIntterexception. Of course, there are other methods in the Preconditions class, which may meet the checks of almost all passing parameters. The advantage of Preconditions is that it is easier to understand in Call Stack, and each method also provides variants of formatted string, such as:
Checkargument (i <j, "expected i <j, but %s> %s", i, j);
Different from the Assert keywords that comes with Java, the method of Preconditions is still effective in the Release version. The reason for this is probably because Java is already very slow.