Java:Java7新语法:修订间差异

来自WHY42
imported>Soleverlee
(以“=switch= =数值字面量= Category:Programe”为内容创建页面)
 
imported>Soleverlee
第1行: 第1行:
=switch=
=switch中使用字符串=
JDK7中允许在switch中使用字符串。但实际在内部实现时,还是通过转换为数字实现的。
<source lang="java">
public int switchFunc(String name){
switch(name){
case "Riguz":
return 1;
case ".Com":
return -1;
default:
break;
}
return 0;
}
</source>


=数值字面量=
=数值字面量=


[[Category:Programe]]
[[Category:Programe]]

2016年6月13日 (一) 02:13的版本

switch中使用字符串

JDK7中允许在switch中使用字符串。但实际在内部实现时,还是通过转换为数字实现的。

public int switchFunc(String name){
	switch(name){
		case "Riguz":
			return 1;
		case ".Com":
			return -1;
		default:
			break;
	}
	return 0;
}

数值字面量