오류1 java nullpoint Exception에 대한 고찰 java 프로그래밍중 NullPointerException이 가장 많이 나오는 아래와 같은 예시에 대해, 미리 염두하고 프로그래밍을 한다면, 대다수의 exception을 회피할 수 있을 것이다. 1. null이 발생할 것 같은 값에 대해서는 미리 예측해서 null체크를 해주기 if (object == null) { // null이면 처리 } else { // null이 아니면 처리 } 2. chaning메서드 호출 자제하기 String str = "Hello"; str = str.substring(0, 3); // NullPointerException 발생 String str = "Hello"; String subStr = str.substring(0, 3); // NullPointerException .. 2023. 6. 22. 이전 1 다음