Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.Object VS java.util.Objects,what's the difference?

Tags:

java

java-7

As we all know,Object is the root class in Java. I found a class named Objects that looks quite similar toObject.

TheisObjects class has confused me for a while. Can anybody tell me when and where we should use the Objects class?

like image 365
andyqee Avatar asked Nov 28 '12 08:11

andyqee


1 Answers

Objects simply contains a set of utility methods that are useful in combination with Object instances. Note that it can't be instantiated (it's final and it has no public constructor) and only contains static methods.

The naming schema of putting utility methods in pluralized-name classes is pretty common in the JDK:

  • Collections
  • Arrays (although strictly speaking there is no corresponding Array class)
  • ...

Other libraries also use this scheme, for example Guava:

  • Maps
  • Strings
  • ...
like image 179
Joachim Sauer Avatar answered Sep 18 '22 12:09

Joachim Sauer