public void setAge(int age) { Preconditions.checkArgument(age > 0, "Age must be greater than 0"); this.age = age; }
public void setName(String name) { this.name = Preconditions.checkNotNull(name, "Name cannot be null"); }In this example, the checkNotNull() method is used to verify that the name parameter being passed into the setName() method is not null. If it is null, an exception will be thrown with the specified error message. The package name of the Preconditions library is com.google.common.base.