Created
November 15, 2012 21:39
-
-
Save wfaler/4081493 to your computer and use it in GitHub Desktop.
java-interdependency-null-bug.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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