Skip to content

Instantly share code, notes, and snippets.

@nherbaut
Created March 6, 2015 18:38
Show Gist options
  • Select an option

  • Save nherbaut/0951a2d3de18a2e20599 to your computer and use it in GitHub Desktop.

Select an option

Save nherbaut/0951a2d3de18a2e20599 to your computer and use it in GitHub Desktop.
type safe list filtering
@SuppressWarnings("unchecked")
public <T extends Property> Collection<T> getList(final Class<T> t){
final Properties props = new Properties();
props.getProperty().add(new Property());
props.getProperty().add(new SmtpProperty());
return (Collection<T>) Collections2.filter(props.getProperty(), new Predicate<Property>() {
@Override
public boolean apply(Property input) {
return t.isInstance(input);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment