I am new to bytebuddy, I would like to dynamically create a class and execute code like below using byte buddy.
public class Formulas{
public double formula1234(FormulaAPI apiReference) {
if(apiReference.getId() > 0){
return apiReference.evaluate("A") * 2;
}else if(apiReference.getId() == 1){
return apiReference.evaluate("B");
}else{
return apiReference.getSum(x1, x2);
}
return null;
}
}
I have the class FormulaAPI
already defined, which has the methods -> evaluate(..)
and getSum(..)
defined in it.
I would like to use byte buddy to dynamically create the class called Formulas and dynamically construct the method formula1234(..)
and the code inside the method.
Is it even possible to construct the if else statements using byte buddy?
Please could you give an example of how this code can be dynamically generated using byte buddy. Any help is appreciated.