Skip to content

Instantly share code, notes, and snippets.

@nathanchen
Created August 14, 2012 04:55
Show Gist options
  • Select an option

  • Save nathanchen/3346383 to your computer and use it in GitHub Desktop.

Select an option

Save nathanchen/3346383 to your computer and use it in GitHub Desktop.
JAVA - 不能为null值
public static <T> T checkNotNull(T reference)
{
if(reference == null)
throw new NullPointerException();
return reference;
}
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)
{
if(reference == null)
throw new NullPointerException(String.valueOf(errorMessage));
return reference;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment