compiled class structure

 

The overall structure of a compiled class is quite simple. Indeed, unlike natively

compiled applications, a compiled class retains the structural information

and almost all the symbols from the source code. In fact a compiled class

contains:

• A section describing the modifiers (such as public or private), the

name, the super class, the interfaces and the annotations of the class.

• One section per field declared in this class. Each section describes the

modifiers, the name, the type and the annotations of a field.

• One section per method and constructor declared in this class. Each section

describes the modifiers, the name, the return and parameter types,

and the annotations of a method. It also contains the compiled code of

the method, in the form of a sequence of Java bytecode instructions.

There are however some differences between source and compiled classes:

• A compiled class describes only one class, while a source file can contain

several classes. For instance a source file describing a class with one inner

class is compiled in two class files: one for the main class and one for the

inner class. However the main class file contains references to its inner

classes, and inner classes defined inside methods contain a reference to

their enclosing method.

 

• A compiled class does not contain comments, of course, but can contain

class, field, method and code attributes that can be used to associate

additional information to these elements. Since the introduction of annotations

in Java 5, which can be used for the same purpose, attributes

have become mostly useless.

• A compiled class does not contain a package and import section, so all

type names must be fully qualified.

Another very important structural difference is that a compiled class contains

a constant pool section. This pool is an array containing all the numeric, string

and type constants that appear in the class. These constants are defined only

once, in the constant pool section, and are referenced by their index in all other

sections of the class file. Hopefully ASM hides all the details related to the

constant pool, so you will not have to bother about it.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值