Item 69. Exceptional Conditions
μ μ΄ νλ¦μμμ μμΈ
class Test {
public static void main(String[] args) {
Mountain[] range = new Mountain[100000000];
for (int i = 0; i < range.length; i++) {
range[i] = new Mountain();
}
// 1. μμΈλ₯Ό μ¨μ 루ν μ’
λ£
long start = System.currentTimeMillis();
try {
int i = 0;
while (true) {
range[i++].climb();
}
} catch (ArrayIndexOutOfBoundsException e) {
// ignore
}
long end = System.currentTimeMillis();
System.out.println("μ€ν μκ° : " + (end - start) / 1000.0 + "μ΄");
// 2. for-each λ¬Έ μ¬μ©
start = System.currentTimeMillis();
for (Mountain mountain : range) {
mountain.climb();
}
end = System.currentTimeMillis();
System.out.println("μ€ν μκ° : " + (end - start) / 1000.0 + "μ΄");
}
static class Mountain {
public void climb() {
}
}
}μν κ²μ¬λ₯Ό ν΅ν μμΈ μ²λ¦¬ μ΅μν
μν κ²μ¬ λ©μλ vs Optional vs νΉμ κ°
Last updated