Java Switch 和 反编译的应用

在Switch语句的使用中,值得注意了解的是下面两点:

1) 如果没有break, 会发生case穿透的现象;

package superlily.control;

public class SwitchDemo {
    public static void main(String[] args) {
        String input = "Super Lily";
        switch (input) {
            case "Super Lily":
                System.out.println("Super Lily!");
//           break;    //after comment it out, "Lily is great!" will be printed out
 
            case "Lily is great!":
                System.out.println("Lily is great!");
                break; //"Nice~" won't be printed out as this block has "break".

            default:
                System.out.println("Nice~");
        }
    }
}

这个程序最后输出

Super Lily!
Lily is great! 

2) case 后面带字符串的话也是转换成数值来做的,我们可以顺便了解一下反编译是怎么回事,怎么通过IDEA反编译class文件并查看(惊喜~~~~撒花~~~~~~)

 

 

从下面这张图里你就能看到字符串在Java里面其实还是数字,java会把它们编译成数字运行我们的程序,是不是很神奇呀~~~~~ :)

 IDEA的反编译功能为我们打开了查看源码的一扇窗, 要好好用起来哟,听说经常查看源码战斗力会暴涨哟~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值