Reputation: 253
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
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
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