Guava: Preconditions.checkNotNull
Guava: Preconditions.checkArgument
JDK: Objects.requireNotNon
NullPointerException or IllegalArgumentException
1. Many APIs in the JDK pro-actively throws NullPointerException. This suggests that throwing NPE is a Java convention.
2. Effective Java Item 60: “Arguably, all erroneous method invocations boil down to an illegal argument or illegal state, but other exceptions are standardly used for certain kinds of illegal arguments and states. If a caller passes null in some parameter for which null values are prohibited, convention dictates that NullPointerException be thrown rather than IllegalArgumentException. Similarly, if a caller passes an out-of-range value in a parameter representing an index into a sequence, IndexOutOfBoundsException should be thrown rather than IllegalArgumentException.”
3. Preconditions.checkNotNull(parameter) is clearer than Preconditions.checkArgument(parameter != null, “parameter can’t be null”)
static import takes first place. Because there was a Bug prior to JDK8.
Prefer dvdPlayer to DVDPlayer. Because you can’t tell HTTPSID(httpSid or httpsId)
Prefer 1TBS to K&R. Because moving codes in K&R may lead messy. 1TBS always has bracket to be clear.
1TBS:
int i;
for (i = 0; i < 10; i++) {
printf(“Hi”);
}
K&R
int i;
for (i = 0; i < 10; i++)
printf(“Hi.”);
stylistic convention