Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Java void visitor
class PartitionFoos {
void doStuff(Collection<Foo> foos) {
final List<Bar> bars = new ArrayList<>();
final List<Baz> bazes = new ArrayList<>();
for (Foo f : foos) {
f.match(new Visitor<Void>() {
@Override
public Void caseBar(Bar b) {
bars.add(b);
return null;
}
@Override
public Void caseBaz(Baz b) {
bazes.add(b);
return null;
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment