vendredi 10 juin 2022

Is there any way of modifying a function internal variable at runtime in Java? [closed]

Is there any way of modifying a function internal variable at runtime in Java?

For example:

public static String foo(String a, String b){
    boolean flag = flagService.select();
    if(flag){
        return a + b;
    }else{
        return a + ',' + b;
    }
}

 public static void main(String[] args) {
     //what I want got: modify flag at runtime and got 2 different result.
     String a = "a";
     String b = "b"
     //TODO: do something modify inner method variable flag = true
     String res1 = foo(a,b);
     //TODO: do something modify inner method variable flag = false
     String res1 = foo(a,b);
     //TODO: contrast res1 and res2
 }

Java Reflection can modify class filed, but can not modify method.

why I want to do that: Every time, Our test engineer should both verity result the of flag true and false. I try to write a freamwok can contrast both result at runtime when difference and do not modify their code.





Aucun commentaire:

Enregistrer un commentaire