首页 > 代码库 > null 之AddAll、Add和Boolean
null 之AddAll、Add和Boolean
@Test
//failed
public void TestListAddAll(){
List<TravelerInfo> travelerInfoSummary=new ArrayList<TravelerInfo>();
travelerInfoSummary.addAll(null);
}
@Test
//success
public void TestListAdd(){
List<TravelerInfo> travelerInfoSummary=new ArrayList<TravelerInfo>();
travelerInfoSummary.add(null);
}
总结null在List中不能addAll,但可以Add
另外,bool型是可以用null赋值的
见:
import org.junit.Test;
public class Tests {
private String name;
private Boolean isMe;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean getIsMe() {
return isMe;
}
public void setIsMe(Boolean isMe) {
this.isMe = isMe;
}
@Test
//success
public void tests(){
Tests t=new Tests();
t.setIsMe(null);
}
}
null 之AddAll、Add和Boolean