Class Objects

java.lang.Object
io.hotmoka.exceptions.Objects

public class Objects extends Object
A collection of run-time checks on objects, with parametric exception type.
  • Constructor Details

    • Objects

      public Objects()
  • Method Details

    • requireNonNull

      public static <T, E extends Exception> T requireNonNull(T obj, ExceptionSupplier<? extends E> onNull) throws E
      Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:
       public Foo(Bar bar) {
           this.bar = Objects.requireNonNull(bar, IllegalArgumentException::new);
       }
       
      Type Parameters:
      T - the type of the reference
      E - the type of the exception thrown if obj is null
      Parameters:
      obj - the object reference to check for nullity
      onNull - the generator of the exception thrown if obj is null
      Returns:
      obj if not null
      Throws:
      E - if obj is null
    • requireNonNull

      public static <T, E extends Exception> T requireNonNull(T obj, String message, ExceptionSupplier<? extends E> onNull) throws E
      Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:
       public Foo(Bar bar) {
           this.bar = Objects.requireNonNull(bar, "bar cannot be null", IllegalArgumentException::new);
       }
       
      Type Parameters:
      T - the type of the reference
      E - the type of the exception thrown if obj is null
      Parameters:
      obj - the object reference to check for nullity
      message - the message of the exception thrown if obj is null
      onNull - the generator of the exception thrown if obj is null
      Returns:
      obj if not null
      Throws:
      E - if obj is null