麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > Java > 正文

淺析Java 反射機制的用途和缺點

2024-07-14 08:41:45
字體:
來源:轉載
供稿:網友

反射的用途 Uses of Reflection

Reflection is commonly used by programs which require the ability to examine or modify the 
runtime behavior of applications running in the Java virtual machine. This is a relatively advanced 
feature and should be used only by developers who have a strong grasp of the fundamentals of the language. With that caveat in mind, reflection is a powerful technique and can enable applications to perform operations which would otherwise be impossible.
反射被廣泛地用于那些需要在運行時檢測或修改程序行為的程序中。這是一個相對高級 
的特性,只有那些語言基礎非常扎實的開發者才應該使用它。如果能把這句警示時刻放在心 
里,那么反射機制就會成為一項強大的技術,可以讓應用程序做一些幾乎不可能做到的事情。

反射的缺點 Drawbacks of Reflection

Reflection is powerful, but should not be used indiscriminately. If it is possible to perform an 
operation without using reflection, then it is preferable to avoid using it. The following concerns 
should be kept in mind when accessing code via reflection.
盡管反射非常強大,但也不能濫用。如果一個功能可以不用反射完成,那么最好就不用。 
在我們使用反射技術時,下面幾條內容應該牢記于心:

性能第一 Performance Overhead

Because reflection involves types that are dynamically resolved, certain Java virtual machine 
optimizations can not be performed. Consequently, reflective operations have slower performance 
than their non-reflective counterparts, and should be avoided in sections of code which are called 
frequently in performance-sensitive applications.
反射包括了一些動態類型,所以 JVM 無法對這些代碼進行優化。因此,反射操作的效 
率要比那些非反射操作低得多。我們應該避免在經常被 執行的代碼或對性能要求很高的程 
序中使用反射。

安全限制 Security Restrictions

Reflection requires a runtime permission which may not be present when running under a 
security manager. This is in an important consideration for code which has to run in a restricted 
security context, such as in an Applet.
使用反射技術要求程序必須在一個沒有安全限制的環境中運行。如果一個程序必須在有 
安全限制的環境中運行,如 Applet,那么這就是個問題了。

內部暴露 Exposure of Internals

Since reflection allows code to perform operations that would be illegal in non-reflective 
code, such as accessing private fields and methods, the use of reflection can result in 
unexpected side-effects, which may render code dysfunctional and may destroy portability. 
Reflective code breaks abstractions and therefore may change behavior with upgrades of the 
platform.
由于反射允許代碼執行一些在正常情況下不被允許的操作(比如訪問私有的屬性和方 
法),所以使用反射可能會導致意料之外的副作用--代碼有功能上的錯誤,降低可移植性。 
反射代碼破壞了抽象性,因此當平臺發生改變的時候,代碼的行為就有可能也隨著變化。


注:相關教程知識閱讀請移步到JAVA教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久精品网址 | 免费毛片视频播放 | 偷偷草网站 | 国产乱弄 | av在线中文| 久久综合久久综合久久 | 高清成人在线 | 91快色| 色呦呦一区二区三区 | 国产欧美在线一区二区三区 | 在线中文日韩 | 久久不射电影网 | 午夜视频你懂的 | 黄色特级毛片 | 蜜桃视频在线观看视频 | 男女一边摸一边做羞羞视频免费 | 19禁国产精品福利视频 | 蜜桃成品人免费视频 | 护士hd欧美free性xxxx | 久久一区二区三区av | 成人男男视频拍拍拍在线观看 | 操操日日 | 精品一区二区三区在线观看国产 | 性感美女一级毛片 | 久艹在线视频 | 婷婷久久综合九色综合色多多蜜臀 | 亚洲精品 在线播放 | 91精品国产综合久久久动漫日韩 | 一本一本久久a久久精品综合小说 | 欧美成人高清在线 | 国产日韩精品欧美一区视频 | 九九热在线视频免费观看 | 91一区二区在线观看 | 国产精品久久久久永久免费 | 色中色激情影院 | 在线播放一区二区三区 | 女18一级大黄毛片免费女人 | 一本到免费视频 | 日韩字幕在线观看 | 亚洲精品欧美在线 | 久久精品视频日本 |