原文:https://juejin.im/book/5c25811a6fb9a049ec6b23ee/section/5ccc66dd518825403b5975fb

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType; public class Foo {
public void print(String s, String args1) {
System.out.println("hello, " + s + " ^^^ " + args1);
} public static void main(String[] args) throws Throwable {
Foo foo = new Foo(); // MethodType methodType = MethodType.methodType(void.class, String.class);
MethodType methodType = MethodType.methodType(void.class, new Class<?>[]{String.class, String.class});
MethodHandle methodHandle = MethodHandles.lookup().findVirtual(Foo.class, "print", methodType);
// methodHandle.invoke(foo, "world");
methodHandle.invoke(foo, "world", "hahaha!");
}
}

动态方法调用秘密武器 —— invokedynamic 指令解读 - MethodHandle的更多相关文章

  1. Java方法调用的字节码指令学习

    Java1.8环境下,我们在编写程序时会进行各种方法调用,虚拟机在执行这些调用的时候会用到不同的字节码指令,共有如下五种: invokespecial:调用私有实例方法: invokestatic:调 ...

  2. Struts2学习笔记 - Action篇<动态方法调用>

    有三种方法可以使一个Action处理多个请求 动态方法调用DMI 定义逻辑Acton 在配置文件中使用通配符 这里就说一下Dynamic Method nvocation ,动态方法调用,什么是动态方 ...

  3. 第三章Struts2 Action中动态方法调用、通配符的使用

    01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...

  4. Struts2 动态方法调用

    01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...

  5. struts之动态方法调用使用通配符

    一.DMI动态方法调用的其中一种改变form表单中action属性的方式已经讲过了.还有两种,一种是改变struts.xml配置文件中action标签中的method属性,来指定执行不同的方法处理不同 ...

  6. struts之动态方法调用改变表单action属性

      一.动态方法调用(DMI:Dynamic Method Invocation) ⒈struts2中同样提供了这个包含多个逻辑业处理的Action,这样就可以在一个Action中进行多个业务逻辑处理 ...

  7. struts2DMI(动态方法调用)

    struts2动态方法调用共有三种方式: 1.通过action元素的method属性指定访问该action时运行的方法 <package name="action" exte ...

  8. Struts2 Action中动态方法调用、通配符的使用

    一.Struts2执行过程图: 二.struts2配置文件的加载顺序 struts-default.xml---struts-plugin.xml---struts.xml 具体步骤: 三.Actio ...

  9. Struts(八):动态方法调用

    动态方法调用:通过url动态调用action中的方法. 默认情况下,Struts的动态方法调用处于禁用状态. 测试定义一个action类: package com.dx.actions; public ...

随机推荐

  1. LInux终端中Ctrl+S卡死

    因为初学Linux,在vim中写东西是总是喜欢按Ctrl+s来保存内容导致终端突然卡主,然后上网查资料发现了Ctrl+s 暂停屏幕输出[锁住终端]而对应的按键是Ctrl+q 恢复屏幕输出[解锁终端]

  2. 树状数据删除(TP5)

    应用场景:类似上图中树状菜单,选中一级菜单 点击上方删除按钮 所有子菜单删除 以下是代码截图(代码基于 TP5)

  3. centos安装virtualbox

    参考:http://www.if-not-true-then-false.com/2010/install-virtualbox-with-yum-on-fedora-centos-red-hat-r ...

  4. 使用postman做接口测试----柠檬不萌!

    目录 一.GET和POST请求的区别 二.http协议 1.http请求分为两个部分 2.http状态码 三.使用postman测试HTTP接口 1.请求方式:get 2.请求方式:post 3.请求 ...

  5. JS检查断网

    window.addEventListener('load', function() { function updateOnlineStatus(event) { var condition = na ...

  6. Myeclipse中dtd代码提示

    1.Myeclipse -->窗口 --> 首选项 2.输入xml c,然后添加 3.输入键 例如:http://struts.apache.org/dtds/struts-2.3.dtd ...

  7. MATLAB图像uint8,uint16,double, rgb转灰度解释

    1.uint8,uint16与double 为了节省存储空间,matlab为图像提供了特殊的数据类型uint8(8位无符号整数),以此方式存储的图像称作8位图像.matlab读入图像的数据是uint8 ...

  8. MOV EAX,DWORD PTR SS:[EBP+8]

    nasm来写可以写成mov eax,dword ptr [ebp + 8]理由:ebp和esp默认是ss段,所以根本不用显式说明.          eax,ebx,ecx,edx,edi,esi默认 ...

  9. 小部分安卓手机 reload 等方法不执行

    自己解析 url 来赋值刷新页面  方法如下:// location.href function updateUrl(url, key) {     var key = (key || 't') + ...

  10. android thread Runnable

    原文链接: http://blog.csdn.net/boyupeng/article/details/6208072 这篇文章中有三点需要提前说明一下, 一: 在android中有两种实现线程thr ...