English 中文(简体)
the,自动编码
原标题:the infame Goto, Java, automatic code

I:

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;
    }
}

我正在自动制定该法。 当发电机到达 go子生产时(而且不知道在哪里),则不知道会发生什么。

我尝试使用标签、突破性、连续性,但并不奏效。

我试图使用内部班(演练)但A和B必须宣布为最后班。 问题A和B必须修改。

如果没有其他解决办法,我将不得不在我的发电机中传播更多的知识。 但是,我更喜欢更简单的解决办法。

任何想法?

提前感谢。

问题回答
public static Object doSmthg(Object A,Object B){
    try {
    if(smthg){ //if is given has an example, it can be any thing else
        doSmthg;
        throw new GotoException(1);
    }
    doSmthg;

    } catch (GotoException e) {
         e.decrementLevel();
        if (e.getLevel() > 0)
            throw e;
    }
    dosmthg1(modifying A and B);
    return an Object;
}

我们可以例外地去做,但是,为了确定正确的“标签”目标,要么必须检查例外信息,要么考虑宽松。

我不知道我是否认为这并非ug。

您可以在标签前的栏目上添加一只my子,并用标签休息作为 go子:

public static Object doSmthg(Object A,Object B){
    label:
    do { // Labeled dummy loop
        if(smthg){ //if is given has an example, it can be any thing else
            doSmthg;
            break label; // This brings you to the point after the labeled loop
        }
        doSmthg;
    } while (false); // This is not really a loop: it goes through only once
    dosmthg1(modifying A and B);
    return an Object;
}

如果你想跳过一些东西,那么:

A
if cond goto c;
B
c: C

你可以这样做。

while (true) {
    A
    if cond break;
    B
}
C




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签