jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zach Cox <z...@cra.com>
Subject Instrument a class and get new instance of it
Date Thu, 13 Jul 2006 22:30:44 GMT
I would like to be able to, at run-time, modify the bytecode of a method of
an existing class and then get a new instance of that class that has the
modified bytecode.  For example, here's a simple class:

public class MyClass
{
  public double getDouble()
  {
    return -1.0;
  }
  
  public String toString()
  {
    return String.valueOf(getDouble());
  }
}

At run-time I'd like to change the value returned in the getDouble method
and then get an instance of MyClass that returns the new value.  I also need
to be able to do this multiple times with different return values.  For
example, I'd create one instance of MyClass that returns 1.0, another
instance that returns 2.0, etc.

I understand the examples that show how to create new ClassGen, MethodGen,
InstructionList, etc and then write out a modified .class file,    but I
want to avoid writing to the filesystem and do everything in memory.  Can
anyone provide any pointers to the BCEL classes/methods  to create a new
instance of a modified JavaClass?

Thanks,
Zach

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


Mime
View raw message