< prev index next >

src/java.base/share/classes/java/lang/constant/DirectMethodHandleDescImpl.java

Print this page




  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 package java.lang.constant;
  26 
  27 import java.lang.invoke.MethodHandle;
  28 import java.lang.invoke.MethodHandles;
  29 import java.lang.invoke.MethodType;
  30 import java.util.Objects;

  31 
  32 import static java.lang.constant.ConstantDescs.CD_void;
  33 import static java.lang.constant.ConstantUtils.validateClassOrInterface;
  34 import static java.lang.constant.ConstantUtils.validateMemberName;
  35 import static java.lang.constant.DirectMethodHandleDesc.Kind.CONSTRUCTOR;
  36 import static java.util.Objects.requireNonNull;
  37 
  38 /**
  39  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a direct
  40  * {@link MethodHandle}.  A {@linkplain DirectMethodHandleDescImpl} corresponds to
  41  * a {@code Constant_MethodHandle_info} entry in the constant pool of a classfile.
  42  */
  43 final class DirectMethodHandleDescImpl implements DirectMethodHandleDesc {
  44 
  45     private final Kind kind;
  46     private final ClassDesc owner;
  47     private final String name;
  48     private final MethodTypeDesc invocationType;
  49 
  50     /**


 199      */
 200     @Override
 201     public boolean equals(Object o) {
 202         if (this == o) return true;
 203         if (o == null || getClass() != o.getClass()) return false;
 204         DirectMethodHandleDescImpl desc = (DirectMethodHandleDescImpl) o;
 205         return kind == desc.kind &&
 206                Objects.equals(owner, desc.owner) &&
 207                Objects.equals(name, desc.name) &&
 208                Objects.equals(invocationType, desc.invocationType);
 209     }
 210 
 211     @Override
 212     public int hashCode() {
 213         return Objects.hash(kind, owner, name, invocationType);
 214     }
 215 
 216     @Override
 217     public String toString() {
 218         return String.format("MethodHandleDesc[%s/%s::%s%s]", kind, owner.displayName(), name, invocationType.displayDescriptor());





 219     }
 220 }


  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 package java.lang.constant;
  26 
  27 import java.lang.invoke.MethodHandle;
  28 import java.lang.invoke.MethodHandles;
  29 import java.lang.invoke.MethodType;
  30 import java.util.Objects;
  31 import java.util.Optional;
  32 
  33 import static java.lang.constant.ConstantDescs.CD_void;
  34 import static java.lang.constant.ConstantUtils.validateClassOrInterface;
  35 import static java.lang.constant.ConstantUtils.validateMemberName;
  36 import static java.lang.constant.DirectMethodHandleDesc.Kind.CONSTRUCTOR;
  37 import static java.util.Objects.requireNonNull;
  38 
  39 /**
  40  * A <a href="package-summary.html#nominal">nominal descriptor</a> for a direct
  41  * {@link MethodHandle}.  A {@linkplain DirectMethodHandleDescImpl} corresponds to
  42  * a {@code Constant_MethodHandle_info} entry in the constant pool of a classfile.
  43  */
  44 final class DirectMethodHandleDescImpl implements DirectMethodHandleDesc {
  45 
  46     private final Kind kind;
  47     private final ClassDesc owner;
  48     private final String name;
  49     private final MethodTypeDesc invocationType;
  50 
  51     /**


 200      */
 201     @Override
 202     public boolean equals(Object o) {
 203         if (this == o) return true;
 204         if (o == null || getClass() != o.getClass()) return false;
 205         DirectMethodHandleDescImpl desc = (DirectMethodHandleDescImpl) o;
 206         return kind == desc.kind &&
 207                Objects.equals(owner, desc.owner) &&
 208                Objects.equals(name, desc.name) &&
 209                Objects.equals(invocationType, desc.invocationType);
 210     }
 211 
 212     @Override
 213     public int hashCode() {
 214         return Objects.hash(kind, owner, name, invocationType);
 215     }
 216 
 217     @Override
 218     public String toString() {
 219         return String.format("MethodHandleDesc[%s/%s::%s%s]", kind, owner.displayName(), name, invocationType.displayDescriptor());
 220     }
 221 
 222     @Override
 223     public Optional<? extends ConstantDesc> describeConstable() {
 224         return null;
 225     }
 226 }
< prev index next >