Monday 29 August 2011

java.util.Objects - new util class in Java 7

In Java 7 we have a new class java.util.Objects. It is a util class for shortening operations on Objects.

We have the following methods:

  • compare(T a, T b, Comparator c):int Returns 0 if the arguments are identical and c.compare(a, b) otherwise. Consequently, if both arguments are null 0 is returned
  • deepEquals(Object a, Object b):boolean Compares objects or Arrays
  • hash(Object... values):int Generates a hash code for a sequence of input values
  • T nonNull(T obj) If obj is not null, return obj else throw a NullPointerException

and other useful methods.

Look for more in javadoc: http://download.oracle.com/javase/7/docs/api/java/util/Objects.html

No comments: