What is cglib?A Byte Code Generation Library which is high level API to generate and transform Java byte code. It is used in various scenarios such as AOP, testing, data access frameworks to generate dynamic proxy objects and intercept field access.
See one example in unit test.
In line 17, a new dynamic proxy class is generated as mock.
In line 19, we tell the proxy, "if get(0) is called on this mock class, then return mocked data "hello, world".
As a result, in line 23 "result: hello, world" will be printed out.
In debugger you can find that the variable in line 17 is mocked by CGLIB:
Its byte code is generated dynamically and stored in variable byte[] b in line 217.
Let's see another example of injecting pre-exit and post-exit ( which ABAPers are very familiar with ) into a given method via dynamic proxy generated by CGLIB:
I have a class MyMEthodExitDemo which has a normal method myFun.
A new dynamic proxy class is generated in method createProxy which has a method with equal name as original class plus custom enhancement covered by class JerryEnhancement.
The pre-exit and post-exit are defined in class JerryEnhancement which implements interface MethodInterceptor defined in CGLIB library. The original method is generated in line 14, with pre-exit before it ( line 13 ) and post-exit after it ( line 15 ).
Execute result:
How can CGLIB be implemented in ABAP?
See my implementation here
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
2. 编写ABAP事件处理程序`after_save`,确保在保存表数据前更新ZTAB表中的ZCREAETDATE和ZCREATETIME字段为当前系统日期和时间。 ```abap FORM after_save. Ztab-ZCREATEDATE = sy-datum. Ztab-ZCREATETIME = sy-...
Unit 1: Introduction to Floorplan Manager (FPM) for Web Dynpro ABAP 1 Exercise 1: Create Components Containing the UIBBs for a Floorplan and Implement Interface IF_FPM_UI_BUILDING_BLOCK Unit 2: FPM...
While most C programmers use APIs and the libraries that implement them in almost every application they write, relatively few programmers create and disseminate new, widely applicable APIs....
在这个“threads pool implement in linux”的测试程序中,我们可以深入探讨线程池的工作原理、优点以及如何在Linux环境中实现。 首先,线程池的核心思想是预先创建一组线程,这些线程存储在一个池中,等待分配的...
Java 中 extend 与 implement 的区别 Java 语言中,extend 和 implement 是两个基本概念,它们之间的区别是非常重要的。extend 用于继承类,而 implement 用于实现接口。在 Java 中,不支持多重继承,但是可以使用...
By the end of this book, you will be able to implement both DL and transfer learning principles in your own systems. What you will learn • Set up your own DL environment with graphics processing ...
This book is for data scientists, machine learning and deep learning practitioners, Cognitive and Artificial Intelligence enthusiasts who want to move one step further in building Convolutional Neural...
本文将围绕“Design_and_Implement_Any_Filter_in_Less_than_60_Seconds”这一主题,深入探讨其核心概念、重要性和实际应用场景。 ### 数字滤波器的重要性 数字滤波器是DSP技术中最强大的工具之一。与传统的模拟...
jcifs_java_implement_cifs jcifs_java_implement_cifs jcifs_java_implement_cifs jcifs_java_implement_cifs jcifs_java_implement_cifs jcifs_java_implement_cifs
- **编写自定义代码**:如果需要更高级的功能,可能还需要编写额外的ABAP代码来实现定制化的值帮助逻辑。 #### 2.4 测试与部署 - **单元测试**:确保每个单独的值帮助功能都能正确运行。 - **集成测试**:在整个...
Implement a simple fully connected neural network in C language and test it on the mnist dataset. / 使用C语言实现一个简单的全连接神经网络,并在mnist数据集上测试。
Written as a tutorial on how to think about, organise and implement programs in scientific computing, this book achieves its goal through an eclectic and wide-ranging collection of projects....
Implement machine learning models in your iOS applications. This short work begins by reviewing the primary principals of machine learning and then moves on to discussing more advanced topics, such as...
7.4.1 Packet Tracer - Implement DHCPv4 Cisco Packet Tracer 思科模拟器 正确答案文件 由于程序问题无法保存激活DHCP端口配置 另加满分步骤截图 可直接上交正确答案文件 本答案版权归mewhaku所有,严禁再次...
Eclipse Implementor插件是专为Eclipse IDE设计的一款实用工具,它主要目的是为了帮助开发者更高效地实现接口或抽象类的方法。在Java编程中,当我们需要为一个接口或抽象类提供具体实现时,手动编写这些方法可能会...
6.4.1 Packet Tracer - Implement Etherchannel Cisco Packet Tracer 思科模拟器 正确答案文件 可直接上交正确答案文件 本答案版权归mewhaku所有,严禁再次转载!!! Copyright @mewhaku 2022 All Rights ...
1.6.1 Packet Tracer - Implement a Small Network Cisco Packet Tracer 思科模拟器 正确答案文件 可直接上交正确答案文件 本答案版权归mewhaku所有,严禁再次转载!!! Copyright @mewhaku 2022 All Rights ...
3.6.1 Packet Tracer - Implement VLANs and Trunking Cisco Packet Tracer 思科模拟器 正确答案文件 可直接上交正确答案文件 本答案版权归mewhaku所有,严禁再次转载!!! Copyright @mewhaku 2022 All Rights ...
You've decided to use Node.js for your next project and you need the skills to implement Node in production. It would be great to have Node experts Alex Young and Marc Harter at your side to help you ...