Skip to content

Instantly share code, notes, and snippets.

@wfaler
Created November 15, 2012 21:39
Show Gist options
  • Save wfaler/4081493 to your computer and use it in GitHub Desktop.
Save wfaler/4081493 to your computer and use it in GitHub Desktop.
java-interdependency-null-bug.java
public class Basket{
private List<LineItem> lineItems = ...
public List<Product> getProductsOfType(String type){
List<Product> products = new ArrayList<Product>();
for(LineItem item : lineItems){
if(item.getProductType().equals(type)
products.add(item.getProduct());
}
return products;
}
public Product getHandset(){
List<Product> handsets = getProductsOfType("handset");
if(handsets.size() > 0)
return handsets.get(0);
return null;
}
public boolean hasHandset(){
return (getHandset() != null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment