为什么判空时str==null||"".equals(str)

public static boolean isEmpty(String str){
  if(str==null||"".equals(str)){
   return true;
  }else{
   return false;
  }
 }

对于以上代码,今天想了下为甚么这样写:

1、当str接收的是文本框传的值时,如果文本框为空,则此时str=""

2、当此方法用于后台时,比如在用次方法时直接粗鲁地给方法传了一个值。如:new了一个book对象,让str=book.getName(),而次book的name属性此时为空:String name=null;   则此时str=null

原文地址:https://www.cnblogs.com/hualidezhuanshen/p/3131285.html