字符串的切换条件如何执行? [英] How switch cases are executed for strings?

查看:61
本文介绍了字符串的切换条件如何执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对switch-case语句有疑问。
这是我的代码:

I have a doubt in switch-case statement. Here is my code :

String month = "April";
switch (month.toLowerCase()) {
            case "january":
                monthNumber = 1;
                break;
            case "february":
                monthNumber = 2;
                break;
            case "march":
                monthNumber = 3;
                break;
            case "april":
                monthNumber = 4;
                break;

依此类推。

I在这种情况下有3个问题:

I have 3 questions in this context:

1)在比较月份和案例值(即案例一月)的同时,案例
二月 ..究竟是什么编译器从以下使用?
-month.equals( case-value)吗?
-month ==个案值?

1) While comparing month with the case values i.e case "January", case "February" .. What is exactly used from the following by compiler ?? - month.equals("case-value") ? - month == case-value ?

2)并且将大小写值在内部转换为StringBuilder / StringStringBuffer或只是将其保留为String对象?

2) And are case-values internally converted to StringBuilder/StringStringBuffer or simply they remain String object ??

3)如何从字节码中得知这一点,即有没有可用的工具可以直接查看编译器生成的代码,以找出事物内部的行为?

3) How I can I know this from byte code i.e is there any tool available using which I can view directly the compiler generated code just to find out how the things behave internally?

推荐答案

3)我相信JDeveloper具有字节码调试器功能。如果不是JDeveloper,请选择我发现的以下工具:

3) I believe JDeveloper has bytecode debugger feature. If JDeveloper is not and option, check out these tools I found:

http://sourceforge.net/projects/jbcd/

http://andrei.gmxhome.de/bytecode/index.html

http://www.drgarbage.com/how-to-debug-bytecode- with-bytecode-visualizer.html

这篇关于字符串的切换条件如何执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆