/** * Factory method that performs validation. * * @param <T> the type of the constant * @param constantToReturn the constant object to return each time in the factory * @return the <code>constant</code> factory. */ @SuppressWarnings("unchecked") // The null factory works for all object types public static <T> Factory<T> constantFactory(final T constantToReturn) { if (constantToReturn == null) { return NULL_INSTANCE; } return new ConstantFactory<>(constantToReturn); }