public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
// 这里定义缓存的边界
static final int low = -128;
static final int high;
int h = 127;
flost精度缺失
2.if的未闭合问题
2.1 开发时常见的有问题写法
写法1,只处理业务需要的数值
public void checkStatus(int status) {
if (status == 1) {
System.out.println("do 1");
} else if (status == 2) {
System.out.println("do 2");
}
}
写法2,只处理需求需要的结果
public void doHandle() {
String errorCode = "do sth";
if (errorCode.equals("1000")) {
// return succes
} else if (errorCode.equals("2000")) {
// return fail
}
}
2.2 问题阐述
其实这样看就很简单了,如果传入的status==3时,假设给一个不存在的数据如何处理业务?
处理结果时,一定是一个闭集,正确的,错误的,任何一个都不能放过
3.for
3.1 for比较推崇的写法
String[] datas = new String[10];
for (int i = 0, len = datas.length; i <; i++) {
System.out.println(datas[i]);
}