English 中文(简体)
案件与Java号案
原标题:Switch Case with string Java

我在很长一段时间后使用java语,发现与其他语言不同的是,java语不支持改道(只有没有 s和 en)。 它背后的原因是什么? 如果其他语文易于使用,那么为什么不 j?

最佳回答

这一特征在 Java7(今年7月公布)。 他们为什么要提前执行? 整批Sun公司以Oracle公司收购,J7公司被真正推迟。

Latest documentation:

问题回答

海事组织称, Java的设计者很聪明才可以离开在Stings的开关。 每当你转而 Str(我承认,有时我也这样做)时,你就应当思考:

  1. Why aren t I using polymorphism here?
  2. At the very least, should I be using an Enum instead?

你可以在 Java7号开关发言中使用“强硬”。

The new Java Version (JDK 7) takes long time to release. That s why you may not be able to know that.... Here is an example how to use strings in switch case...

   option = scanner.nextLine();
   switch (option) {
    case "1": System.out.println("Hello");break;
    case "2": break;
    case "3": break;
    case "4": break;
    case "5": break;
    default: System.out.println("Invalid option. Please try again..."); break;
  }

Not6和 be2的另一种方式是:

String runFct = 
        queryType.equals("eq") ? "method1":
        queryType.equals("L_L")? "method2":
        queryType.equals("L_R")? "method3":
        queryType.equals("L_LR")? "method4":
            "method5";
Method m = this.getClass().getMethod(runFct);
m.invoke(queryField);




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

热门标签