Reputation: 554
I have some class A
without source code and this class uses some class B
with 2 methods like #get(): int
and set #set(int value): void
from standard Java library!
Can I substitute this 2 methods or all class to change some functionality of this class A
?
For example, this class A
uses standard class B
for saving some information, but I want uses this another container for some operations. It possible?
Upvotes: 0
Views: 336
Reputation: 340783
You can use some bytecode manipulation libraries like java-bytecode-asm. However a much simpler approach is to use aspectj and weave classes, either statically or dynamically. AspectJ can even weave standard Java library (rt.jar
).
Upvotes: 2
Reputation: 3509
I am not sure but I believe what you are trying to do is Extend the class and then override the method.
And as kirk woll says, that does not look like java.
Upvotes: 1