Answer the question
In order to leave comments, you need to log in
Is it possible to add a new method to a class at runtime?
For example, there is a simple empty class without properties and methods. Is it possible to add methods and properties there, and then call them through reflection?
Update
And still so thoughts aloud. JRebel somehow replaces classes with modified (added remote) methods and properties right at runtime. How?
Answer the question
In order to leave comments, you need to log in
Any manipulations (at the JVM level) with classes at runtime are possible using libraries that work with bytecode (the same cglib or asm) and custom javaagent. There are projects like JRebel, DCEVM or Spring Loaded that allow you to change the logic at runtime (again using the tools already mentioned).
Using such tools in production is contraindicated, and in development they are useless with TDD.
UPD: answer to the question: it is possible, but is it necessary?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question