Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes you can, one approach is to use some form of byte code manipulation (e.g. <a href="http://www.csg.is.titech.ac.jp/~chiba/javassist/" rel="nofollow noreferrer">javassist</a>, <a href="http://asm.ow2.org/" rel="nofollow noreferrer">ASM</a>, BCEL) or a higher level AOP library sit on top of one of these tools, e.g. <a href="http://www.eclipse.org/aspectj/" rel="nofollow noreferrer">AspectJ</a>, JBoss AOP.</p> <p>Note: most JDO libraries do this for handling persistence.</p> <p>Here is an example using javassist:</p> <pre><code>public class Person { private String firstName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } } public static void rewritePersonClass() throws NotFoundException, CannotCompileException { ClassPool pool = ClassPool.getDefault(); CtClass ctPerson = pool.get("Person"); CtClass ctSet = pool.get("java.util.LinkedHashSet"); CtField setField = new CtField(ctSet, "updatedFields", ctPerson); ctPerson.addField(setField, "new java.util.LinkedHashSet();"); CtMethod method = ctPerson.getDeclaredMethod("setFirstName"); method.insertBefore("updatedFields.add(\"firstName\");"); ctPerson.toClass(); } public static void main(String[] args) throws Exception { rewritePersonClass(); Person p = new Person(); p.setFirstName("foo"); Field field = Person.class.getDeclaredField("updatedFields"); field.setAccessible(true); Set&lt;?&gt; s = (Set&lt;?&gt;) field.get(p); System.out.println(s); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload