ClosableIterable<Triple> triples = graph.find(ANY_TRIPLE);
try {
for (Triple triple : triples) {
System.out.println("Graph: " + triple);
}
} finally {
triples.iterator().close();
}
try {
for (Triple triple : triples) {
System.out.println("Graph: " + triple);
}
} finally {
triples.iterator().close();
}
Using "ClosableIterators.with" this becomes:
with(graph.find(ANY_TRIPLE), new Function<Void, ClosableIterable<Triple>>() {
public Void apply(ClosableIterable<Triple> object) {
for (Triple triple : object) {
System.out.println("Graph: " + triple);
}
return null;
}
});
It's typically one line less but that's not that much of an improvement.
public Void apply(ClosableIterable<Triple> object) {
for (Triple triple : object) {
System.out.println("Graph: " + triple);
}
return null;
}
});
1 comment:
Though it's not the line count that is important; it's the compositional aspects of the code. You can pull the latter one apart and reason about the smaller parts independently.
Java gets in the way in terms of syntax and type system. The latter hindrance is much more catastrophic in terms of assessing Java for practical use, yielding a consistent conclusion.
Post a Comment