English 中文(简体)
能否在没有住所的情况下使用LABEL块?
原标题:Can a LABEL block be used without loop?
  • 时间:2009-12-21 12:50:18
  •  标签:
  • java
  • label

能否在没有住所的情况下使用LABEL块? 任何例子?

问题回答

rel=“noreferer”>Here是使用标签和打破声明而不作假的一个例子:

        block1: {
            if (a < 0) {
                break block1;
            }
            if (b < 0) {
                break block1;
            }
            return a + b;
        }
  public static void main(String[] args)
  {
    hello: break hello;
  }

www.un.org/Depts/DGACM/index_spanish.htm 但为什么在代码栏上使用标识?

我的申请通常是在“强势”变量(或除char、 by、 short、英南以外的任何东西)上的开关。

“为了做一个ome,你必须打破一些鸡蛋”。

<>>Example:

String key = "scrambled";
eggs: {
    if ("do-nothing".equals(key)) break eggs;
    if ("scrambled".equals(key)) {
        ;//scramble code here
        break eggs;
    }
    if ("fried".equals(key)) {
        ;//fry code here
        break eggs;
    }
    //default behaviour goes here
    //or maybe throw an exception
}

Ok, ok, Sometimes, to make an omelette, 你必须杀死少数人。”

<<>替代物>

  • Java 7 allows String as the switch.
  • An Enum workaround using MyEnum.valueOf(str) can be made to work.
  • A switch on the String (or Object) s hashcode plus some more if-then-else if is possible but would only make sense for lots of possibilities, in which case the whole thing is probably due for an overhaul.

当然:

private boolean isSafe(String data) {

    validation: {

        if (data.contains("voldemort")) {
            break validation;
        }
        if (data.contains("avada")) {
            break validation;
        }
        if (data.contains("kedavra")) {
            break validation;
        }
        return true;
    }
    return false;
}

@DragonBorn:这是不可能的。 你们只能继续或打破其范围内的标签,例如:

    label1: for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            System.out.println(i + " " + j);
            if (i == j) {
                continue label1;
            }
        }
    }

生产:

0 0
1 0
1 1
2 0
2 1
2 2
3 0
3 1
3 2
3 3

如果你想要某种不可读的法典:

int i = 1;
int j = 1;
label: switch (i) {
case 1:
    switch (j) {
    case 1:
        break label;
    }
default:
    System.out.println("end");
}

不含<条码>;将印刷“端”。 <编码>突破性标签;将ski印。





相关问题
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 ...