package com.xdl.java7;
import org.junit.Test;
import com.xdl.ienum.XuDaoLong_Final_Val;
public class Day_One {
/**
* java7string新特性switch与枚举类型,二进制,字面量
*
* @param nameString
* @param genderString
* @return
*/
public static String switch_sex(String nameString, String genderString) {
/*采用emun方法定义常量,支持switch*/
XuDaoLong_Final_Val male = XuDaoLong_Final_Val.MALE;
String flagString = "";
/* genderString=null;表达式的值不能为null,否则抛出空指针 */
switch (male) {
case MALE:
flagString = nameString + "先生";
break;
/*
* 等价上面的case子句 case "\u7537": flagString =nameString +"先生"; break;
* 实际上字符串和case子句在编译被替换成了对应的哈希值,使JVM看到的仍然是整数类型兼容的类型
*/
case FEMALE:
flagString = nameString + "女士";
break;
default:
break;
}
return flagString;
}
@Test
public void TestSwitchIsCorrect() {
System.out.println(switch_sex("许道龙", "男"));
System.out.println("二进制"+0b101101);
System.out.println("八进制"+0101101);
System.out.println("十六进制"+0X101101);
/*数值字面量下使用下划线,但不允许_100,120_,0b10101*/
System.out.println(1_000_000_000);
}
/*经JAD反编译就这样紫了=.=:
* public static String switch_sex(String nameString, String genderString)
{
String flagString = "";
String str1;
switch ((str1 = genderString).hashCode()) {
case 22899: if (str1.equals("女")) break;
case 30007: if ((goto 106) && (str1.equals("男")))
{
flagString = nameString + "先生";
return flagString;
flagString = nameString + "女士"; }
break;
}
return flagString;
}*/
}