1 /* 2 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /** 27 * <em>Functional interfaces</em> provide target types for lambda expressions 28 * and method references. Each functional interface has a single abstract method 29 * to which the lambda expression's parameter and return types are matched or 30 * adapted. Functional interfaces can provide a target type in multiple contexts, 31 * such as assignment context, method invocation, or cast context: 32 * 33 * <pre>{@code 34 * Predicate<String> p = String::isEmpty; 35 * 36 * stream.filter(e -> e.getSize() > 10)... 37 * 38 * stream.map((ToIntFunction) e -> e.getSize())... 39 * }</pre> 40 * 41 * <p>The interfaces in this package are functional interfaces used by the JDK, 42 * and are available to be used by user code as well. While they do not identify 43 * a complete set of function shapes to which lambda expressions might be adapted, 44 * they provide enough to cover common requirements. 45 * 46 * <p>The interfaces in this package are annotated with @{link FunctionalInterface}. 47 * This annotation is not a requirement for the compiler to recognize an interface 48 * as a functional interface, but merely an aid to capture design intent and enlist the 49 * help of the compiler in identifying accidental violations of design intent. 50 * 51 * <p>The functional interfaces in this package follow an extensible naming convention, 52 * as follows: 53 * 54 * <ul> 55 * <li>There are several basic function shapes, including {@link java.util.function.Function} ({@code T -> R}), 56 * {@link java.util.function.Consumer} ({@code T -> void}), 57 * {@link java.util.function.Predicate} ({@code T -> boolean}), 58 * and {@link java.util.function.Supplier} ({@code () -> T}). 59 * </li> 60 * <li>Function shapes have a natural arity based on how they are most commonly used. 61 * The basic shapes can be modified by an arity prefix to indicate a different arity, 62 * such as {@link java.util.function.BiFunction} ({@code (T, U) -> R}). 63 * </li> 64 * <li>There are additional derived function shapes which extend the basic function 65 * shapes, including {@link java.util.function.UnaryOperator} (extends {@code Function}) and 66 * {@link java.util.function.BinaryOperator} (extends {@code BiFunction}). 67 * </li> 68 * <li>Type parameters of functional interfaces can be specialized to primitives with 69 * additional type prefixes. To specialize the return type for a type that has both 70 * generic return type and generic arguments, we prefix {@code ToXxx}, as in 71 * {@link java.util.function.ToIntFunction}. Otherwise, type arguments are specialized left-to-right, 72 * as in {@link java.util.function.DoubleConsumer} or {@link java.util.function.ObjIntConsumer}. 73 * (The type prefix {@code Obj} is used to indicate that we don't want to specialize this parameter, 74 * but want to move on to the next parameter.) These schemes can be combined as in {@code IntToDoubleFunction}. 75 * </li> 76 * <li>If there are specialization prefixes for all arguments, the arity prefix may be left 77 * out (as in {@link java.util.function.ObjIntConsumer}). 78 * </li> 79 * </ul> 80 * 81 * @see java.lang.FunctionalInterface 82 */ 83 package java.util.function;