Skip to content

Instantly share code, notes, and snippets.

@evacchi
Last active February 23, 2018 09:24
Show Gist options
  • Save evacchi/b2dd2fb7979bc3d775d2cc061d303a54 to your computer and use it in GitHub Desktop.
Save evacchi/b2dd2fb7979bc3d775d2cc061d303a54 to your computer and use it in GitHub Desktop.
Ghetto Type Aliases using Generic Bounds
//
// the implementation for this class is in the package-private
// abstract class below. We are using type parameters to fake type aliases.
// Scroll down for details
//
public class DefinitionsBuildingContext
extends DefinitionsContextHelper<
/*EdgeT = */
Edge<ViewConnector<BPMNViewDefinition>,
Node<? extends View<? extends BPMNViewDefinition>, ?>>,
/*NodeT = */
Node<View<? extends BPMNViewDefinition>,
Edge<ViewConnector<BPMNViewDefinition>,
Node<? extends View<? extends BPMNViewDefinition>, ?>>>
> {
public DefinitionsBuildingContext(
Graph<DefinitionSet,
Node<View<? extends BPMNViewDefinition>,
Edge<ViewConnector<BPMNViewDefinition>,
Node<? extends View<? extends BPMNViewDefinition>, ?>>>> graph) {
super(graph);
}
}
//
// this is sort-of a hack: we don't have type aliases in Java
// so we use this abstract class to bind a type-parameter to this horribly long
// Node, Edge declarations (because Node, Edge are... mutually recursive... erm)
// so we declare EdgeT, NodeT to "extend" the type we want to alias
// then in the concrete instance we actually **bind** them to the exact type
//
abstract class DefinitionsContextHelper<
EdgeT extends
Edge<ViewConnector<BPMNViewDefinition>,
Node<? extends View<? extends BPMNViewDefinition>, ?>>,
NodeT extends
Node<View<? extends BPMNViewDefinition>, EdgeT>
> {
private final Map<String, ? extends NodeT> nodes;
private final Node firstNode;
public DefinitionsContextHelper(Graph<DefinitionSet, NodeT> graph) {
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment