Lolmister
Lolmister

Reputation: 253

Changing a method of an instance from another class in java

Im trying to change the method of just one instance from another class. Is this possible, and if so how can I do it?

Im trying to rewrite the entire method durring runtime. I only want the method to be changed for one instance of the class, and all the other instance's methods should stay the same. I hope that clears up some confusion

Upvotes: 1

Views: 105

Answers (2)

Neil Girardi
Neil Girardi

Reputation: 4943

I think you need to provide more details and perhaps some sample code to get a sufficient answer. That being said, if class Foo extends class Bar, class Foo can override a method of class Bar. Is that what you're trying to do?

Upvotes: 0

Antimony
Antimony

Reputation: 39491

No this is not possible.

Method definitions are stored by class, not instance (and are immutable anyway). One thing you can do is to store a callable object per instance and call that.

Upvotes: 2

Related Questions