Java Reference
In-Depth Information
boolean.class; };
public void isValidSwitchType(Class typeClass) {
String switchType = typeClass.getSimpleName();
boolean valid = true;
switch (switchType) {
case "char":
case "byte":
case "short":
case "int":
System.out.print("Primitive type "
+ switchType);
break;
case "Character":
case "Byte":
case "Short":
case "Integer":
System.out.print("Boxed primitive type "
+ switchType);
break;
case "String":
case "Enum":
System.out.print(switchType);
break;
default: // invalid switch type
System.out.print(switchType);
valid = false;
}
System.out.println(" is " + (valid ? "" : "not ")
+ "a valid switch type.");
}
public static void main(String[] args) {
SwitchTypeChecker check = new SwitchTypeChecker();
check.isValidSwitchType(varTypeClass('7'));
check.isValidSwitchType(varTypeClass(7));
check.isValidSwitchType(varTypeClass(777.7d));
check.isValidSwitchType(varTypeClass((short)7));
Search WWH ::




Custom Search