【ASM】字节码操作 Label 如何使用 生成 if 语句

在这里插入图片描述

1.概述

前置文章:【ASM】字节码操作 Label 介绍 顺序、选择和循环

视频:【ASM】字节码操作 Label 如何使用

在程序中,有三种基本控制结构:顺序、选择和循环。我们现在已经知道,MethodVisitor 类是用于生成方法体的代码

  1. 如果没有Label学的参与,那么MethodVisitor类只能生成”顺序”结构的代码;
  2. 如果有Label类的参与,MethodVisitor 类就能生成选择"和“循环“结构的代码。

在本文当中,我们来介绍Label类。

如果查看Label类的API文档,就会发现下面的描述,分成了三个部分。

  1. 第一部分,Label 类上是什么(What) ;
  2. 第二部分,在哪些用到Label类(Where) ;
  3. 第三部分,在编写ASM代码

过程中,如何使用Label类(How) , 或者说,Label 类与Instruction的关系。

  1. A position in the bytecode of a method.
  2. Labels are used for jump, goto, and switch instructions, and for try catch bloc

猜你喜欢

转载自blog.csdn.net/qq_21383435/article/details/124808728