javaassist opensource framework is the initials of the"Java Programming Assistant" , it makes Java bytecode manipulation simple and easy. you can manipulate the behaviors of the java the following aspects:
1 soruce code level
2 bytecode level
hibernate use the javaassist to instead to the cglib in version 3.3, its function is similar to the cglib ,it can implement the lazy loading and generate the po objects
for examples:
package antlr;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
public class TestAntlr {
public static void main(String[] args) throws Exception {
ClassPool cp = ClassPool.getDefault();
CtClass cc = cp.get("antlr.Hello");
CtMethod m = cc.getDeclaredMethod("say");
// m.setBody("{System.out.println(\"s\");}");
m.insertBefore("System.out.println(\"ss\");");
Class c = cc.toClass();
Hello h = (Hello)c.newInstance();
h.say();
// ClassPool cp = ClassPool.getDefault();
// CtClass cc = cp.get("java.lang.String");
// CtMethod m = cc.getDeclaredMethod("toString");
//// m.setBody("{System.out.println(\"s\");}");
//
//// m.insertBefore("System.out.println(\"ss\");");
// Class c = cc.toClass();
// String h = (String)c.newInstance();
// h.toString();
}
}
package antlr;
class Hello{
public void say() {
System.out.println("Hello");
}
}
分享到:
相关推荐
In a recent poll, Hibernate was among the top five tools used by many Java developers every day. This shows that SQL databases are still the preferred technology for reliable data storage and ...
A Testing Framework used in the web Testing A Testing Framework used in the web Testing A Testing Framework used in the web Testing A Testing Framework used in the web Testing A Testing Framework used...
design patterns that are used with Hibernate, such as the Data Access Object (DAO). You see how you can test your Hibernate application easily and learn what other best practices are relevant if you ...
The FEM is commonly used in the design and development of products, especially where structural analysis is involved. The simple object model of the Java™ programming language lends itself to ...
The second is OpenFOAM®, an open source framework used in the development of a range of CFD programs for the simulation of industrial scale flow problems. With over 220 figures, numerous examples ...
This application note describes the CAN protocol used in the STM32 microcontroller bootloader. It details each supported command. This document applies to the STM32 products embedding bootloader ...
Put simply, the new features in Java 8 along with the (less-obvious) changes in Java 9 are the biggest change to Java in the 21 years since Java 1.0 was released. Nothing has been taken away, so all ...
Hibernate 4.x continues to be the most popular out-of-the-box, open source framework solution for Java persistence and data/database accessibility techniques and patterns and it works well with the ...
The structure of the chapter is very similar, so I hope the reader won’t find diffi- culties in establishing comparisons or understanding the differences between specific problems AI is being used ...
This updated edition of Java in a Nutshell not only helps experienced Java programmers get the most out of Java versions 9 through 11, it’s also a learning path for new developers. Chock full of ...
The architecture section provides an overview of the core components and design patterns used in Hibernate. - **Overview**: This introduces the main concepts and components of Hibernate's ...
Library (net.datastructures) of Java constructs used in the book Problems database and search engine Student hints to all exercises in the book Instructor resources, including solutions to ...
Our results show that if clear channel assessment (CCA) is not used in the overlapping channel, the throughput in legacy BSS is almost zero, while the throughput of 20/40 MHz BSS decreases ...
"Java for the Web with Servlets, JSP, and EJB: A Developer’s Guide to J2EE Solutions" by Budi Kurniawan is a comprehensive guide aimed at helping developers master web programming in Java. The book ...
Library (net.datastructures) of Java constructs used in the book Problems database and search engine Student hints to all exercises in the book Instructor resources, including solutions to ...
In this new book, you'll learn how the module system improves reliability and maintainability, and how it can be used to reduce tight coupling of system components. Foreword by Kevlin Henney. ...
Learn to use the Java Persistence API (JPA) and other related APIs as found in the Java EE 8 platform from the perspective of one of the specification creators. A one-of-a-kind resource, this in-depth...
On the other hand, by going through this book you’re going to learn a lot about object-oriented programming by seeing objects used in many different situations. If your knowledge of objects is ...
Hibernate: A Developer's Notebook shows you how to use Hibernate to automate persistence: you write natural Java objects and some simple configuration files, and Hibernate automates all the ...