Imagine you have a Java code like this :
public class MyClass {
public static Object doSmthg(Object A,Object B){
if(smthg){ //if is given has an example, it can be any thing else
doSmthg;
GOTO label;
}
doSmthg;
label;
dosmthg1(modifying A and B);
return an Object;
}
}
I am generating the Code automatically. When the generator arrive at the moment of generating the goto (and it does not know it is in the if block), it has no knowledge of what will be afterwards.
I tried using labels,break,continue but this does not work.
I tried to use an internal class (doing dosmthg1) but A and B must be declared final. The problem is A and B have to be modified.
If there is no other solutions, I will have to propagate more knowledge in my generator. But I would prefer a simpler solution.
Any ideas ?
Thanks in advance.
One can do gotos with exception, but for targeting the correct "label" one either has to check the exception message or think of a nesting level.
I do not know whether I find this not uglier.