Created
December 27, 2010 03:02
-
-
Save anonymous/755824 to your computer and use it in GitHub Desktop.
hn.post.id2040835
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
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