Class文件详解 (1)[3]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

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 = 22

const index = 1, flag = 1
 const type = Utf8
     length = 22
      value = example/test/TestClass

const 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/Object

const 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 = id

const index = 6, flag = 1
 const type = Utf8
     length = 1
      value = I

本文关键:Class文件详解 (1)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top