源码家

  • 开发语言:
  • Java
  • 源码大小:
  • 1.71M
  • 源码类别:
  • Java语言基础
  • 文件格式:
  • .pdf

源码介绍

【源码简介】java反射实战

【源码截图】

【核心源码】

contents
preface xiii
acknowledgments xv
about this book xvii
about the title xx
about the cover illustration xxi
1
A few basics 1
1.1 Reflection’s value proposition 3
1.2 Enter George the programmer 4
Choosing reflection 5

Programming a reflective solution 6
1.3 Examining running programs 8
1.4 Finding a method at runtime 10
1.5 Representing types with class objects 12
Representing primitive types 13

Representing interfaces 13
Representing array types 14
1.6 Understanding method objects 14
Using dynamic invocation 15

Using primitives with dynamic
invocation 16

Avoiding invocation pitfalls 17
1.7 Diagramming for reflection 19
viii CONTENTS
1.8 Navigating the inheritance hierarchy 20
Introspecting the inheritance hierarchy 22

Exposing some
surprises 23

Another reflective circularity 24
1.9 Summary 26
2
Accessing fields reflectively 27
2.1 Serializing objects 28
Serializing to XML 29

Choosing reflection 30
Designing serialization with reflection 30
2.2 Finding fields at runtime 31
2.3 Understanding field objects 33
2.4 Getting and setting field values 34
2.5 Examining modifiers 35
Introducing Member 36

Interface introspection pitfall 37
Introspecting for instance variables 37
2.6 Accessing nonpublic members 38
2.7 Working with arrays 40
2.8 Serialization: putting it all together 41
Serializing each component 43

Serializing instance variables 43
2.9 Using reflective serialization 45
2.10 Summary 48
3
Dynamic loading and reflective construction 49
3.1 George’s deployment problem 50
Designing with patterns 51

Programming a reflective solution 52
Enhancing the factory method with reflection 54

Combining
benefits of delegation and reflection 54
3.2 Loading classes dynamically 55
Basics of forName 55

Getting array classes 56
Primitives and forName 56
3.3 Constructing objects reflectively 57
Reflective construction basics 57

Using constructor objects 57
Constructing arrays reflectively 59
3.4 Designing for dynamic loading 60
Disadvantages of reflective construction with arguments 61
Initializing through an interface 62
CONTENTS ix
3.5 Implementing deserialization 63
Initiating deserialization 64

Constructing the instances 65
Restoring the object structure 66
3.6 George’s serialization: limitations 69
No interaction with readObject or writeObject 69

No handling of
final instance variables 70

Only no-argument constructors 70
No handling of illegal XML characters 70

Performance 71
3.7 Summary 71
4
Using Java’s dynamic proxy 73
4.1 Working with proxies 74
4.2 George’s tracing problem 76
4.3 Exploring Proxy 77
Understanding invocation handlers 79
Handling the methods of Object 80
4.4 Implementing a tracing proxy 81
4.5 A note on factories 84
4.6 Chaining proxies 86
Structuring invocation handlers for chaining 86

Implementing
a synchronized proxy 88
■ Chaining the two proxies
89
4.7 Stubbing interfaces for unit testing 90
Examining stubs 90

Design for stubbing with Proxy 91
Implementation of stubbing with Proxy 93
4.8 Generating SOAP remote proxies 99
4.9 Pitfalls of using Proxy 103
4.10 Summary 105
5
Call stack introspection 107
5.1 George’s logging problem 108
5.2 Performing call stack introspection 111
5.3 Logging with call stack introspection 112
5.4 Pitfalls 114
5.5 Class invariant checking 115
5.6 Summary 120
x CONTENTS
6
Using the class loader 121
6.1 George’s test problem 122
6.2 Essentials of ClassLoader 123
Understanding the delegation model 123

Programming a simple
class loader 127

Reinitializing static fields: a solution 128
6.3 Multiple namespaces 130
6.4 Dynamic class replacement 132
Designing for replacement 132

Implementing replacement 134
Simplifying assumptions 137
6.5 Additional considerations 138
Security 139

Don’t reinvent the wheel 139

Modifying bytecode in a
class loader 140

When not to invent a specialized class loader 140
Additional examples 141

Endorsed Standards Override 142
6.6 Summary 142
7
Reflective code generation 143
7.1 Reflective code generation 143
7.2 Generating HelloWorld.java 145
7.3 Class-to-class transformation framework 147
C2C 148

Args 152

C2CConstructor 154
C2CTransformation 157
7.4 Example: extent management 159
7.5 C2IdentitySubclassOfC and its subclasses 168
7.6 UQueue 170
7.7 Using the framework 173
7.8 Relation to Aspect-Oriented Programming 175
7.9 Summary 176
8
Design patterns 179
8.1 Singleton 181
8.2 Decorator class-to-class transformations 187
8.3 Proxy (again) 197
8.4 Another composition feature 201
CONTENTS xi
8.5 Problematic issues in writing
class-to-class transformations 201
8.6 Summary 204
9
Evaluating performance 207
9.1 Evaluating performance 207
9.2 Categorizing performance impact 209
9.3 Using microbenchmarks 210
9.4 Benchmarking two ways to use Proxy 214
9.5 Understanding Amdahl’s Law 218
9.6 Applying Amdahl’s Law 221
9.7 Summary 223
10
Reflecting on the future 225
10.1 Looking forward: Java 1.5 226
JSR 14—Generics 227
■ JSR 175—Annotation Facility
229
JSR 201—Language extensions 234
Impact of Java 1.5 on reflective code 235
10.2 Looking forward: competition for Java reflection 236
C# 236

Python 236

Smalltalk 236

CLOS 237
Ruby 237

Perl 237
10.3 Looking forward: Aspect-Oriented Programming 237
10.4 Looking forward: your career 238
appendix A Reflection and metaobject protocols 241
appendix B Handling compilation errors in the
“Hello world!” program 253
appendix C UML 256
glossary 258
references 260
index 267
xiii
preface

  • 商品评价
  • 交易规则
  • 交易流程

  • 发货方式

  • 1、自动:在上方保障服务中标有自动发货的商品,拍下后,将会自动收到来自卖家的商品获取(下载)链接;

    2、手动:未标有自动发货的的商品,拍下后,卖家会收到邮件、短信提醒,也可通过QQ或订单中的电话联系对方。

  • 交易周期

  • 1、源码默认交易周期:自动发货商品为1天,手动发货商品为3天,买家有1次额外延长3天交易周期的权利;

    2、若上述交易周期双方依然无法完成交易,任意一方可发起追加周期(1~7天)的请求,对方同意即可延长。

  • 退款说明

  • 1、描述:源码描述(含标题)与实际源码不一致的(例:描述PHP实际为ASP、描述的功能实际缺少、版本不符等);

    2、演示:有演示站时,与实际源码小于95%一致的(但描述中有"不保证完全一样、有变化的可能性"类似显著声明的除外);

    3、发货:手动发货源码,在卖家未发货前,已申请退款的;

    4、安装:免费提供安装服务的源码但卖家不履行的;

    5、收费:额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外);

    6、其他:如质量方面的硬性常规问题等。

    注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。

  • 1注意事项

  • 1、源码家会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全!

    2、源码家无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别;

    3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外);

    4、在没有"无任何正当退款依据"的前提下,商品写有"一旦售出,概不支持退款"等类似的声明,视为无效声明;

    5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准);

    6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在互站上所留的QQ、手机号沟通,以防对方不承认自我承诺。

    7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于互站介入快速处理。

  • 互站声明

  • 1、源码家作为第三方中介平台,依据交易合同(商品描述、交易前商定的内容)来保障交易的安全及买卖双方的权益;

    2、非平台线上交易的项目,出现任何后果均与互站无关;无论卖家以何理由要求线下交易的,请联系管理举报。