Java Reference
In-Depth Information
public static void printNameWithSuplier(String name, Supplier<String> messageSupplier) {
// Test name for not null. Generate a NullPointerException if it is null.
Objects.requireNonNull(name, messageSupplier);
// Print the name if the above statement dod not throw an exception
System.out.println("Name is " + name);
}
}
Hash Code is 79643668
null is equal to null: true
null is equal to XYZ: false
toString(null) is null
toString(null, "XXX") is XXX
Name is Doug Dyer
Name is required.
Name is Babalu
Name is required. Error generated on 2014-01-18T06:02:43.713Z
Summary
Classes in Java are arranged in a tree-like hierarchy. Classes in the tree have a superclass-subclass relationship. The
Object
class is at the root of the class hierarchy. It is the superclass of all classes in Java. The
Object
class is in the
java.lang
package. The
Object
class contains methods that are automatically available in all classes. Some methods
have been implemented and some not. Classes can also reimplement some methods in the
Object
class. A reference
variable of the
Object
class can store the reference of any reference type in Java.
Java 7 added a utility class
Objects
in the
java.util
package. The class contains convenience methods to
compute hash codes for objects. Most of the methods in this class exist to deal with
null
value gracefully. Java 8 has
added some additional methods to this class for the new lambda language feature.