001/* 002 * Copyright (C) 2007 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014 015package com.google.common.base; 016 017import com.google.common.annotations.GwtCompatible; 018import org.jspecify.annotations.Nullable; 019 020/** 021 * Legacy version of {@link java.util.function.Supplier java.util.function.Supplier}. Semantically, 022 * this could be a factory, generator, builder, closure, or something else entirely. No guarantees 023 * are implied by this interface. 024 * 025 * <p>The {@link Suppliers} class provides common suppliers and related utilities. 026 * 027 * <p>As this interface extends {@code java.util.function.Supplier}, an instance of this type can be 028 * used as a {@code java.util.function.Supplier} directly. To use a {@code 029 * java.util.function.Supplier} in a context where a {@code com.google.common.base.Supplier} is 030 * needed, use {@code supplier::get}. 031 * 032 * <p>See the Guava User Guide article on <a 033 * href="https://github.com/google/guava/wiki/FunctionalExplained">the use of {@code Function}</a>. 034 * 035 * @author Harry Heymann 036 * @since 2.0 037 */ 038@GwtCompatible 039@FunctionalInterface 040public interface Supplier<T extends @Nullable Object> extends java.util.function.Supplier<T> { 041 /** 042 * Retrieves an instance of the appropriate type. The returned object may or may not be a new 043 * instance, depending on the implementation. 044 * 045 * @return an instance of the appropriate type 046 */ 047 @Override 048 @ParametricNullness 049 T get(); 050 051 /** 052 * <i>May</i> return {@code true} if {@code object} is a {@code Supplier} that behaves identically 053 * to this supplier. 054 * 055 * <p><b>Warning: do not depend</b> on the behavior of this method. 056 * 057 * <p>Historically, {@code Supplier} instances in this library have implemented this method to 058 * recognize certain cases where distinct {@code Supplier} instances would in fact behave 059 * identically. However, as code migrates to {@code java.util.function}, that behavior will 060 * disappear. It is best not to depend on it. 061 */ 062 @Override 063 boolean equals(@Nullable Object object); 064}