在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例Java语言基础 → java反射实战

java反射实战

Java语言基础

下载此实例
  • 开发语言:Java
  • 实例大小:1.71M
  • 下载次数:12
  • 浏览次数:56
  • 发布时间:2022-11-09
  • 实例类别:Java语言基础
  • 发 布 人:qwer23
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: java 实战 反射

实例介绍

【实例简介】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

标签: java 实战 反射

实例下载地址

java反射实战

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警