Type information

1, runtime type information (RTTI) allows you to discover and use type information while a 

program is running.

2, the class object;

to understand how RTTI works in Java, you must first know how type information is

represented at run time. this is accomplished through a special kind of object called the class

object, which contains information about the class. in fact, the class object is used to create all

of the "regular" objects of your class. java performs its RTTI using the class object, even 

if you're doing something like a cast. the class Class also has a number of other ways you

can use RTTI.

there's one Class object for each class that is part of your program.

all classes are loaded into the JVM dynamically, upon the first use of a class. this happens

when the program makes the first reference to a static member of that class. it turns out that

the constructor is also a static method of a class, even though the static keyword is not used for

a constructor. therefor, creating a new object of that class using the new operatior also counts as a 

reference to a static member of the class.

the call to static Class.forName() is being made for its side effect, which is to load the classs

if it isn't already loaded. 

there are actually three steps in preparing a class for use:

1), loading, which is performed by the class loader. this finds the bytecodes (usually, but not 

necessarily, on your disk in your classpath) and creates a Class object from those bytecodes.

2), linking, the link phase verifies the bytecodes in the class, allocates storage for static fields,

and if necessary, resolves all references to other classes made by this class.

3), initialization. if there's a superclass, initialize that. execute static initializers and static initialization

blocks.

if a static final value is a "compile-time constant", that value can be read without casing the

class to be initialized. making a field static and final, however, does not guarantee this behavior:

because it cannot be a compile-time constant.

if a static field is not final, accessing it always requires linking ( to allocate storage for the field)

and initializaion (to initiaalize that storage) before it can be read.



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值