jdk/src/share/classes/java/util/function/package-info.java
author mduigou
Tue, 23 Jul 2013 13:20:11 -0700
changeset 19040 7b25fde2a4ed
parent 19033 13013b301bd0
child 19850 93b368e54c1c
permissions -rw-r--r--
8019840: Spec updates for java.util.function Reviewed-by: mduigou, chegar Contributed-by: brian.goetz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14670
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
     1
/*
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
14670
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
     4
 *
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    10
 *
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    15
 * accompanied this code).
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    16
 *
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    20
 *
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    23
 * questions.
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    24
 */
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    25
14670
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    26
/**
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    27
 * <em>Functional interfaces</em> provide target types for lambda expressions
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    28
 * and method references.  Each functional interface has a single abstract
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    29
 * method, called the <em>functional method</em> for that functional interface,
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    30
 * to which the lambda expression's parameter and return types are matched or
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    31
 * adapted.  Functional interfaces can provide a target type in multiple
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    32
 * contexts, such as assignment context, method invocation, or cast context:
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    33
 *
19033
13013b301bd0 8020948: Fix doclint issues in misc package-info.java files
darcy
parents: 16011
diff changeset
    34
 * <pre>{@code
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    35
 *     // Assignment context
19033
13013b301bd0 8020948: Fix doclint issues in misc package-info.java files
darcy
parents: 16011
diff changeset
    36
 *     Predicate<String> p = String::isEmpty;
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    37
 *
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    38
 *     // Method invocation context
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    39
 *     stream.filter(e -> e.getSize() > 10)...
14670
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    40
 *
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    41
 *     // Cast context
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    42
 *     stream.map((ToIntFunction) e -> e.getSize())...
19033
13013b301bd0 8020948: Fix doclint issues in misc package-info.java files
darcy
parents: 16011
diff changeset
    43
 * }</pre>
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    44
 *
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    45
 * <p>The interfaces in this package are general purpose functional interfaces
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    46
 * used by the JDK, and are available to be used by user code as well.  While
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    47
 * they do not identify a complete set of function shapes to which lambda
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    48
 * expressions might be adapted, they provide enough to cover common
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    49
 * requirements. Other functional interfaces provided for specific purposes,
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    50
 * such as {@link java.io.FileFilter}, are defined in the packages where they
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    51
 * are used.
14670
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    52
 *
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    53
 * <p>The interfaces in this package are annotated with
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    54
 * {@link java.lang.FunctionalInterface}. This annotation is not a requirement
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    55
 * for the compiler to recognize an interface as a functional interface, but
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    56
 * merely an aid to capture design intent and enlist the help of the compiler in
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    57
 * identifying accidental violations of design intent.
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    58
 *
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    59
 * <p>Functional interfaces often represent abstract concepts like functions,
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    60
 * actions, or predicates.  In documenting functional interfaces, or referring
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    61
 * to variables typed as functional interfaces, it is common to refer directly
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    62
 * to those abstract concepts, for example using "this function" instead of
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    63
 * "the function represented by this object".
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    64
 *
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    65
 * <p>The functional interfaces in this package follow an extensible naming
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    66
 * convention, as follows:
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    67
 *
14670
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
    68
 * <ul>
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    69
 *     <li>There are several basic function shapes, including
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    70
 *     {@link java.util.function.Function} (unary function from {@code T} to {@code R}),
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    71
 *     {@link java.util.function.Consumer} (unary function from {@code T} to {@code void}),
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    72
 *     {@link java.util.function.Predicate} (unary function from {@code T} to {@code boolean}),
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    73
 *     and {@link java.util.function.Supplier} (nilary function to {@code R}).
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    74
 *     </li>
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    75
 *
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    76
 *     <li>Function shapes have a natural arity based on how they are most
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    77
 *     commonly used.  The basic shapes can be modified by an arity prefix to
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    78
 *     indicate a different arity, such as
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    79
 *     {@link java.util.function.BiFunction} (binary function from {@code T} and
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    80
 *     {@code U} to {@code R}).
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    81
 *     </li>
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    82
 *
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    83
 *     <li>There are additional derived function shapes which extend the basic
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    84
 *     function shapes, including {@link java.util.function.UnaryOperator}
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    85
 *     (extends {@code Function}) and {@link java.util.function.BinaryOperator}
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    86
 *     (extends {@code BiFunction}).
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
    87
 *     </li>
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    88
 *
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    89
 *     <li>Type parameters of functional interfaces can be specialized to
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    90
 *     primitives with additional type prefixes.  To specialize the return type
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    91
 *     for a type that has both generic return type and generic arguments, we
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    92
 *     prefix {@code ToXxx}, as in {@link java.util.function.ToIntFunction}.
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    93
 *     Otherwise, type arguments are specialized left-to-right, as in
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    94
 *     {@link java.util.function.DoubleConsumer}
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    95
 *     or {@link java.util.function.ObjIntConsumer}.
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    96
 *     (The type prefix {@code Obj} is used to indicate that we don't want to
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    97
 *     specialize this parameter, but want to move on to the next parameter,
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    98
 *     as in {@link java.util.function.ObjIntConsumer}.)
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
    99
 *     These schemes can be combined, as in {@code IntToDoubleFunction}.
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
   100
 *     </li>
19040
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
   101
 *
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
   102
 *     <li>If there are specialization prefixes for all arguments, the arity
7b25fde2a4ed 8019840: Spec updates for java.util.function
mduigou
parents: 19033
diff changeset
   103
 *     prefix may be left out (as in {@link java.util.function.ObjIntConsumer}).
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
   104
 *     </li>
14670
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
   105
 * </ul>
16011
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
   106
 *
890a7ed97f6c 8004561: Additional functional interfaces, extension methods and name changes
mduigou
parents: 14670
diff changeset
   107
 * @see java.lang.FunctionalInterface
14670
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
   108
 */
964ac9f1463c 8001634: Initial set of functional interface types
mduigou
parents:
diff changeset
   109
package java.util.function;