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 com.google.errorprone.annotations.CanIgnoreReturnValue; 019import javax.annotation.CheckForNull; 020import org.checkerframework.checker.nullness.qual.Nullable; 021 022/** 023 * Legacy version of {@link java.util.function.Function java.util.function.Function}. 024 * 025 * <p>The {@link Functions} class provides common functions and related utilities. 026 * 027 * <p>As this interface extends {@code java.util.function.Function}, an instance of this type can be 028 * used as a {@code java.util.function.Function} directly. To use a {@code 029 * java.util.function.Function} in a context where a {@code com.google.common.base.Function} is 030 * needed, use {@code function::apply}. 031 * 032 * <p>This interface is now a legacy type. Use {@code java.util.function.Function} (or the 033 * appropriate primitive specialization such as {@code ToIntFunction}) instead whenever possible. 034 * Otherwise, at least reduce <i>explicit</i> dependencies on this type by using lambda expressions 035 * or method references instead of classes, leaving your code easier to migrate in the future. 036 * 037 * <p>See the Guava User Guide article on <a 038 * href="https://github.com/google/guava/wiki/FunctionalExplained">the use of {@code Function}</a>. 039 * 040 * @author Kevin Bourrillion 041 * @since 2.0 042 */ 043@GwtCompatible 044@FunctionalInterface 045@ElementTypesAreNonnullByDefault 046public interface Function<F extends @Nullable Object, T extends @Nullable Object> 047 extends java.util.function.Function<F, T> { 048 @Override 049 @CanIgnoreReturnValue // TODO(kevinb): remove this 050 @ParametricNullness 051 T apply(@ParametricNullness F input); 052 053 /** 054 * <i>May</i> return {@code true} if {@code object} is a {@code Function} that behaves identically 055 * to this function. 056 * 057 * <p><b>Warning: do not depend</b> on the behavior of this method. 058 * 059 * <p>Historically, {@code Function} instances in this library have implemented this method to 060 * recognize certain cases where distinct {@code Function} instances would in fact behave 061 * identically. However, as code migrates to {@code java.util.function}, that behavior will 062 * disappear. It is best not to depend on it. 063 */ 064 @Override 065 boolean equals(@CheckForNull Object object); 066}