Skip to content

Instantly share code, notes, and snippets.

Created December 27, 2010 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/755824 to your computer and use it in GitHub Desktop.
Save anonymous/755824 to your computer and use it in GitHub Desktop.
hn.post.id2040835
package hn.post.id2040835;
public class TiredOfInsufficientTyping {
public static void main(String[] args) {
// is this really that bad?
final BasicBlockGraph<FooOp> graph = new BasicBlockGraph<FooOp>();
graph.getRoot().getOp().invoke();
// I want to believe ..
FooOp theOp = graph.getRoot().getOp();
BasicBlockVertex<FooOp> root = graph.getRoot();
}
/* your generic library that defines the semantics */
abstract static class AbstractOp {
abstract Object invoke() ;
}
static class Vertex <O extends AbstractOp>{
private O op;
public O getOp() { return op; }
// ...
}
static class Edge <V extends Vertex<? extends AbstractOp>> {
V[] vertices;
}
static class Graph<V extends Vertex<? extends AbstractOp>, E extends Edge<?>> {
private V root;
public V getRoot() { return root; }
}
/* your special case with specific implementations */
static class BlockEdge extends Edge<BasicBlockVertex<AbstractOp>>{
// specialized blah blah
}
static class BasicBlockVertex<O extends AbstractOp> extends Vertex<O> {
// specialized blah blah
}
static class BasicBlockGraph<O extends AbstractOp> extends Graph<BasicBlockVertex<O>, BlockEdge>{
// specialized blah blah
}
static class FooOp extends AbstractOp {
Object invoke() {
return "Foo!";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment