Overwriting a declared method?

Hello, I'm messing with something Java based, I want to modify it a bit. My code is simply this:
Method xyzMethod = XYZ.class.getDeclaredMethod("a", int.class, int.class, int.class, int.class, Random.class);
Method xyzMethod = XYZ.class.getDeclaredMethod("a", int.class, int.class, int.class, int.class, Random.class);
Now the issue is that unlike the Field class, Method doesn't seem to have a set method. So, if I wanted to override this function - how?
6 Replies
JavaBot
JavaBot2mo ago
This post has been reserved for your question.
Hey @Lort533! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
stechy1
stechy12mo ago
Hi, what do you mean by "override this function"? The field has a "set" method, because it allows you to set the value of the field.
0x150
0x1502mo ago
you dont just "set" a method. you need to generate a new class that overrides that method, and then you need to load that class and call its a() method really depends on what you want to do here do you want to: 1. change the a() method for everyone globally retroactively? 2. make one instance of XYZ with a different a() implementation?
JavaBot
JavaBot2mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Lort533
Lort533OP2mo ago
happened to solve it already, but it turned out there is only one instance of that class so I did the latter of what you've mentioned, I originally thought I need to override the method for all existing instances of the class
JavaBot
JavaBot2mo ago
Post Closed
This post has been closed by <@236915391933317120>.

Did you find this page helpful?