之前我們已經對ASM進行的詳細的介紹,需要的朋友們可以點擊這裡:java字節碼框架ASM的深入學習
JVM的類型簽名對照表
比如,java方法是
reee對應的型別簽字就是
long f (int n, String s, int[] arr);
再比如,java方法是
f (ILjava/lang/String;[I)J
那對應的型別簽字就是接下來要核對ASMreee
那對應的型別簽字是用來驗證兩個private void hi(double a, List<String> b);
hi (DLjava/util/List;)V
public class Test { public static void main(String[] args) throws Exception { ClassPrinter printer = new ClassPrinter(); //读取静态内部类Bazhang ClassReader cr = new ClassReader("Test$Bazhang"); cr.accept(printer, 0); } //静态内部类 static class Bazhang { public Bazhang(int a) { } private long f (int n, String s, int[] arr){ return 0; } private void hi(double a, List<String> b){ } } static class ClassPrinter extends ClassVisitor { public ClassPrinter() { super(Opcodes.ASM5); } @Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { super.visit(version, access, name, signature, superName, interfaces); //打印出父类name和本类name System.out.println(superName + " " + name); } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { //打印出方法名和类型签名 System.out.println(name + " " + desc); return super.visitMethod(access, name, desc, signature, exceptions); } } }
java/lang/Object Test$Bazhang <init> ()V f (ILjava/lang/String;[I)J hi (DLjava/util/List;)V