swith和如何在idea中查看源码
Posted lly-start
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swith和如何在idea中查看源码相关的知识,希望对你有一定的参考价值。
package com.struct;
?
public class SwitchDomn01 {
public static void main(String[] args) {
char grade = ‘A‘;
//case穿透 //swith 匹配一个具体的值
?
switch (grade){
case ‘A‘:
System.out.println("youxiu");
break;
case ‘B‘:
System.out.println("lainghao");
break;
case ‘C‘:
System.out.println("jige");
break;
case ‘D‘:
System.out.println("hh");
break;
default:
System.out.println("weizhi");
}
}
}
?
如何查看源码
源码所在路径:打开路径 进入文件找到class文件
将class文件复制到idea所属文件夹 再在其中打开
在idea中打开
package com.struct;
?
public class SwithDomn02 {
public static void main(String[] args) {
String name = "ling";
?
?
?
switch (name){
case "li":
System.out.println("li");
break;
case "ling":
System.out.println("ling");
break;
default:
System.out.println("hai a");
}
}
}
?
源码:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
?
package com.struct;
?
public class SwithDomn02 {
public SwithDomn02() {
}
?
public static void main(String[] args) {
String name = "ling";
byte var3 = -1;
switch(name.hashCode()) {
case 3453:
if (name.equals("li")) {
var3 = 0;
}
break;
case 3321846:
if (name.equals("ling")) {
var3 = 1;
}
}
?
switch(var3) {
case 0:
System.out.println("li");
break;
case 1:
System.out.println("ling");
break;
default:
System.out.println("hai a");
}
?
}
}
?
以上是关于swith和如何在idea中查看源码的主要内容,如果未能解决你的问题,请参考以下文章