2

I heard that many frameworks (Struts, Spring, Hibernate, AspectJ) use bytecode manipulation internally. What are the compelling reasons to use bytecode manipulation? I'm expecting a answer with at least a use-case for each particular framework.

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Nuwan Arambage
  • 683
  • 2
  • 7
  • 13

1 Answers1

12

These frameworks manipulate the bytecode of your classes so that they can add support for their features into them. For example, Hibernate may code into getters/setters of a class in order to help it track when the entity has been updated (become dirty) and/or to return proxies of sub-entities that contain code to do lazy-loading.

Aspectj manipulates bytecode in order to add the aspects that you have requested it to enforce. For example, if you want to add advice to all the methods of a class to log when they are invoked, then aspectj may add bytecode (that performs that logging) to each method.

jhouse
  • 2,674
  • 1
  • 18
  • 17