2013年10月1日星期二

Interview questions , the following code is what is wrong with the

1. if(username.equals("zxx"){}
2. int  x = 1;
return x==1?true:false;

------ Solution ------------------------------------- -------
first one username may be null null pointer exceptions should be placed in front of the zxx
second trinocular operation is redundant, direct return x == 1 on the line
------ Solution ---------------- ----------------------------
 on the first floor are finished
1 when comparing constants and variables , constants, up front , to avoid variable is empty due to a null pointer
2 return x == 1 is enough, back ? : superfluous , pointless
------ For reference only - -------------------------------------

Thank
- ---- For reference only ---------------------------------------
< br /> Thank

没有评论:

发表评论