it-day

"".equals 와 equals("") 차이 알려주세요

별지킴Lee 2023. 11. 23. 15:34

 

public Message send(ReciveDto reciveDto) throws Exception {
 try {
       if(reciveDto.getNm().equals("") || reciveDto.getNm() == null){}
 }catch (Exception e){
 }

이거는 null이 파라미터로 오면 Exception 가지는데

public Message send(ReciveDto reciveDto) throws Exception {
 try {
       if("".equals(reciveDto.getNm()) || reciveDto.getNm() == null){}
 }catch (Exception e){
 }

이거는 왜 안갈까요?!!!!!!!!!!!!!!!!!!!!!!!!

 

reciveDto.getNm().equals("")

"".equals(reciveDto.getNm())

차이인데 하..............................

 

결국

StringUtils.isEmpty를 사용했음

StringUtils.isEmpty( reciveDto.getNm() )