< prev index next >

src/java.base/share/classes/java/lang/invoke/MethodHandle.java

Print this page
rev 53560 : 8218022: Repeated words typos in java.base
Reviewed-by: alanb, lancea
Contributed-by: Andrey Turbanov <turbanoff@gmail.com>
   1 /*
   2  * Copyright (c) 2008, 2018, 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


1066       * Adapts this method handle to be {@linkplain #asVarargsCollector variable arity}
1067       * if the boolean flag is true, else {@linkplain #asFixedArity fixed arity}.
1068       * If the method handle is already of the proper arity mode, it is returned
1069       * unchanged.
1070       * @apiNote
1071       * <p>This method is sometimes useful when adapting a method handle that
1072       * may be variable arity, to ensure that the resulting adapter is also
1073       * variable arity if and only if the original handle was.  For example,
1074       * this code changes the first argument of a handle {@code mh} to {@code int} without
1075       * disturbing its variable arity property:
1076       * {@code mh.asType(mh.type().changeParameterType(0,int.class))
1077       *     .withVarargs(mh.isVarargsCollector())}
1078       * <p>
1079       * This call is approximately equivalent to the following code:
1080       * <blockquote><pre>{@code
1081       * if (makeVarargs == isVarargsCollector())
1082       *   return this;
1083       * else if (makeVarargs)
1084       *   return asVarargsCollector(type().lastParameterType());
1085       * else
1086       *   return return asFixedArity();
1087       * }</pre></blockquote>
1088       * @param makeVarargs true if the return method handle should have variable arity behavior
1089       * @return a method handle of the same type, with possibly adjusted variable arity behavior
1090       * @throws IllegalArgumentException if {@code makeVarargs} is true and
1091       *         this method handle does not have a trailing array parameter
1092       * @since 9
1093       * @see #asVarargsCollector
1094       * @see #asFixedArity
1095      */
1096     public MethodHandle withVarargs(boolean makeVarargs) {
1097         assert(!isVarargsCollector());  // subclass responsibility
1098         if (makeVarargs) {
1099            return asVarargsCollector(type().lastParameterType());
1100         } else {
1101             return this;
1102         }
1103     }
1104 
1105     /**
1106      * Makes an <em>array-collecting</em> method handle, which accepts a given number of trailing


   1 /*
   2  * Copyright (c) 2008, 2019, 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


1066       * Adapts this method handle to be {@linkplain #asVarargsCollector variable arity}
1067       * if the boolean flag is true, else {@linkplain #asFixedArity fixed arity}.
1068       * If the method handle is already of the proper arity mode, it is returned
1069       * unchanged.
1070       * @apiNote
1071       * <p>This method is sometimes useful when adapting a method handle that
1072       * may be variable arity, to ensure that the resulting adapter is also
1073       * variable arity if and only if the original handle was.  For example,
1074       * this code changes the first argument of a handle {@code mh} to {@code int} without
1075       * disturbing its variable arity property:
1076       * {@code mh.asType(mh.type().changeParameterType(0,int.class))
1077       *     .withVarargs(mh.isVarargsCollector())}
1078       * <p>
1079       * This call is approximately equivalent to the following code:
1080       * <blockquote><pre>{@code
1081       * if (makeVarargs == isVarargsCollector())
1082       *   return this;
1083       * else if (makeVarargs)
1084       *   return asVarargsCollector(type().lastParameterType());
1085       * else
1086       *   return asFixedArity();
1087       * }</pre></blockquote>
1088       * @param makeVarargs true if the return method handle should have variable arity behavior
1089       * @return a method handle of the same type, with possibly adjusted variable arity behavior
1090       * @throws IllegalArgumentException if {@code makeVarargs} is true and
1091       *         this method handle does not have a trailing array parameter
1092       * @since 9
1093       * @see #asVarargsCollector
1094       * @see #asFixedArity
1095      */
1096     public MethodHandle withVarargs(boolean makeVarargs) {
1097         assert(!isVarargsCollector());  // subclass responsibility
1098         if (makeVarargs) {
1099            return asVarargsCollector(type().lastParameterType());
1100         } else {
1101             return this;
1102         }
1103     }
1104 
1105     /**
1106      * Makes an <em>array-collecting</em> method handle, which accepts a given number of trailing


< prev index next >