sp; System.out.println(" const type = Fieldref");
n16 = input.readShort();
System.out.println("class index = " + n16 + " (where to find the class)");
n16 = input.readShort();
System.out.println("nameAndType = " + n16 + " (where to find the NameAndType)");
break;
case 10: // method reference
System.out.println(" const type = Methodref");
n16 = input.readShort();
System.out.println("class index = " + n16 + " (where to find the class)");
n16 = input.readShort();
System.out.println("nameAndType = " + n16 + " (where to find the NameAndType)");
break;
case 11: // interface method reference
System.out.println(" const type = InterfaceMethodref");
n16 = input.readShort();
System.out.println("class index = " + n16 + " (where to find the interface)");
n16 = input.readShort();
System.out.println("nameAndType = " + n16 + " (where to find the NameAndType)");
break;
case 12: // name and type reference
System.out.println(" const type = NameAndType");
n16 = input.readShort();
System.out.println(" name index = " + n16 + " (where to find the name)");
n16 = input.readShort();
System.out.println(" descripter = " + n16 + " (where to find the descriptor)");
break;
default:
throw new RuntimeException("Invalid constant pool flag: " + flag);
}
}
}
输出结果为:
magic number = 0xCAFEBABE
Version = 48.0
constant pool size = 22const index = 1, flag = 1
const type = Utf8
length = 22
value = example/test/TestClassconst index = 2, flag = 7
const type = Class
index = 1 (where to find the class name)const index = 3, flag = 1
const type = Utf8
length = 16
value = java/lang/Objectconst index = 4, flag = 7
const type = Class
index = 3 (where to find the class name)const index = 5, flag = 1
const type = Utf8
length = 2
value = idconst index = 6, flag = 1
const type = Utf8
length = 1
value = I