熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Javascript >> 正文

Class文件詳解 (2)

2022-06-13   來源: Javascript 

  繼續分析Class文件的結構
  
  上次讀取了constant pool緊接著是這個類或接口的Access flagsJVM定義的關於class或interface的Access flags有
  
  private static short ACC_PUBLIC  = x;
  private static short ACC_FINAL   = x;
  private static short ACC_SUPER   = x;
  private static short ACC_INTERFACE = x;
  private static short ACC_ABSTRACT = x;
  
  // read access flags:
  short access_flags = inputreadShort();
  Systemoutprint(Access flags:);
  if((access_flags & ACC_PUBLIC) == ACC_PUBLIC)
  Systemoutprint( public);
  if((access_flags & ACC_FINAL) == ACC_FINAL)
  Systemoutprint( final);
  if((access_flags & ACC_SUPER) == ACC_SUPER)
  Systemoutprint( super);
  if((access_flags & ACC_INTERFACE) == ACC_INTERFACE)
  Systemoutprint( interface);
  if((access_flags & ACC_ABSTRACT) == ACC_ABSTRACT)
  Systemoutprint( abstract);
  Systemoutprintln();
  
  然後是this class和super class
  
  // read this class and super class:
  short this_class_index = inputreadShort();
  short super_class_index = inputreadShort();
  Systemoutprintln(This class = + this_class_index);
  Systemoutprintln(Super class = + super_class_index);
  
  根據this class的index可以從constant pool中得到這個class的信息super class也一樣每個class都有super class只有Object的super class index=
  
  接下來是這個class繼承了多少個interface和每個interface在constant pool中的index
  
  // read interfaces count:
  short interfaces_count = inputreadShort();
  Systemoutprintln(Interfaces count = + interfaces_count);
  // read each interface:
  for(int i=; i<=interfaces_count; i++) {
  short interface_index = inputreadShort();
  Systemoutprintln(No + i + interface index = + interface_index);
  }
  
  結果如下
  
  Access flags: public final super
  This class =
  Super class =
  Interfaces count =

From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25408.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.