dzav
dzav

Reputation: 554

Substitute methods in class without source code

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

Answers (2)

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340783

You can use some bytecode manipulation libraries like . However a much simpler approach is to use and weave classes, either statically or dynamically. AspectJ can even weave standard Java library (rt.jar).

Upvotes: 2

Kevin
Kevin

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

Related Questions