Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you have a few options, none of them nice and all stink to high heaven of an architectural issue with how you're addressing the problem you're presented with.</p> <p><strong>Delegating Wrapper</strong></p> <p>Create a <strong>DelegaingFoo</strong> class that looks like this:</p> <pre><code>class DelegatingFoo { Callable callMe; public DelegatingFoo(Callable callMe) { this.callMe = callMe; } public void fighters(){ calLMe.call(); } }; </code></pre> <p>Instanciate this instead, passing in a Callable object into the constructor as you are above. this disjoints the code you want to run from the bit that injects it.</p> <p><strong>Use a JVM language</strong></p> <p>Compile to something that can be run through <strong>javax.script</strong>, such as BeanShell, Groovy, etc. Depending on what you're ultimately doing, this may be a viable option.</p> <p><strong>Customised Classloader</strong></p> <p>If you have the option of using an alternative class loader (which presents it's own issues), which is something that would be fraught with it's own issues, and create something really quite complex. If you decide to consider this seriously, then looking at something like the OSGi class loading framework may give you some clues (it may even, at a stretch, be suitable).</p> <p><strong>Bytecode Manipulation</strong></p> <p>There are a few libraries which will help with bytecode munging / interception / generation / alteration on the fly:</p> <ul> <li>BECL - <a href="http://commons.apache.org/bcel/" rel="nofollow">http://commons.apache.org/bcel/</a></li> <li>CGLib - <a href="http://cglib.sourceforge.net/" rel="nofollow">http://cglib.sourceforge.net/</a></li> </ul> <p><strong>WARNING</strong></p> <p>It should be noted that all the above are hacks, with increasing depravity as you go down them. I would get my architecture peer reviewed ASAP as I would put money on there being a cleaner &amp; clearer approach to what you're doing.</p> <p>Remember, code you write should be easier to read - otherwise you're creating a maintenance headache for yourself (or future project owners).</p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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