NullPointerException NullPointerException은 개발자가 한번이라도 만나봤을 에러이다. 그정도로 흔하게 일어나는 에러로, 이는 “자바의 모든 객체는 NULL일 수 있다.”” 라는 말을 확인시켜준다. NullPointerExcpetion이 발생하는 경우를 예시로 보자. public static getCarInsurancename(Person pserson) { return person.getCar().getInsurance().getName(); } 위 코드에서 getCar()를 실행한 후의 값이 NULL이라면? 차가 없는 사람은 존재할 수 있다. person.getCar()의 값이 NULL인데 getInsurance()가 실행되면 여기서 NullPointerException이..
Read more
collection
Map null값 체크 //collections4 compile "org.apache.commons:commons-collections4:4.0" MapUtils를 사용하여 map 객체의 null 체크가 가능하다. Map map = new HashMap; MapUtils.isEmpty(map); MapUtils.isEmpty() /** * Null-safe check if the specified map is empty. * * Null returns true. * * @param map the map to check, may be null * @return true if empty or null * @since 3.2 */ public static boolean isEmpty (final Map map..
Read more