The Javadoc for Preconditions from the Google Guava library states that:
Projects that use com.google.common should generally avoid using Objects.requireNonNull (Object) . Instead, use checkNotNull (Object) or Verify.verifyNotNull (Object) as appropriate. (The same goes for messages accepting congestion.)
What is the motivation for this recommendation? I can not find in Javadok.
I mean, they pretty much do the same thing, and in these cases it's usually better to use the standard API (for example, the people behind Joda-Time now recommend that people use java.time , pretty much discounting their own framework )
As an example, these two lines of input validation do the same thing:
class PreconditionsExample { private String string; public PreconditionsExample(String string) { this.string = Objects.requireNonNull(string, "string must not be null"); this.string = Preconditions.checkNotNull(string, "string must not be null"); } }
source share