Last active
August 29, 2015 14:15
-
-
Save kevinpet/64fdecea4ac7aec4338c to your computer and use it in GitHub Desktop.
Java void visitor
This file contains 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
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