if(null check)-else vs try catch(NullPointerException) which is more efficient?

后端 未结 6 1731
春和景丽
春和景丽 2020-12-28 17:48

Which of the following three functions is more efficient;

  public String getmConnectedDeviceName1() {
        if(null != mServerDevice) {
            retur         


        
6条回答
  •  既然无缘
    2020-12-28 18:17

    I definitely agree with the rest of answers. To not saying the same exactly, I will only tell you, that now I'm introducing to a quite big commercial source code which has been written for about 3 years and I have not seen any statement using the try-catch approach you have mentioned of; although there were lot of to check for null ;)

提交回复
热议问题