BEGIN;
验证代码如下:
public static void main(String[] args) {
Long id = null;
System.out.println(test1(id));
System.out.println(test2(id));
System.out.println(test3(id));
System.out.println(test4(id));
}
private static String test1(Long id) {
try {
if(0 == id || null == id) return “test1 --> 判断代码成功。”;
else return “test1 --> 判断代码错误!”;
} catch (Exception e) {
return “test1 --> Exception”;
}
}
private static String test2(Long id) {
try {
if(id == 0 || null == id) return “test2 --> 判断代码成功。”;
else return “test2 --> 判断代码错误!”;
} catch (Exception e) {
return “test2 --> Exception”;
}
}
private static String test3(Long id) {
try {
if(null == id || 0 == id) return “test3 --> 判断代码成功。”;
else return “test3 --> 判断代码错误!”;
} catch (Exception e) {
return "test3 --> " + e.getLocalizedMessage();
}
}
private static String test4(Long id) {
try {
if(null == id || id == 0) return “test4 --> 判断代码成功。”;
else return “test4 --> 判断代码错误!”;
} catch (Exception e) {
return "test4 --> " + e.getLocalizedMessage();
}
}
结果如下:
test1 --> Exception
test2 --> Exception
test3 --> 判断代码成功。
test4 --> 判断代码成功。
OK,结束。
END;