Search code examples
javajava-bytecode-asmbytecode-manipulation

How to replace a method return type?


This is just a learning experiment for fun. I'm toying with bytecode manipulation.

I'm just messing around for learning with asm in java. I wonder if it is possible to replace the return type of a method from an interface.

Let's say that I have an interface:

interface Modifiable {
    Integer a();
}

Should I create a copy of the class, load it into the class loader, and then modify this new interface?

If it were possible, this change would be available in compile time? So to speak, that my ide autocomplete those new methods.


Solution

  • You can't change the return type without changing the interface itself.