example.fruit.makeiteasy
Class TreeMaker

java.lang.Object
  extended by example.fruit.makeiteasy.TreeMaker

public class TreeMaker
extends Object

Java's broken type system makes it harder than it should be to define Properties and Instantiators for generic types.

To see the problem, inline the call to fruit() or emptyList() in the instantiator below. As soon as the result of a generic method is passed as a parameter, instead of assigned to a local variable or constant, the code stops compiling!

The solution is to define local variables or constants to force the bindings of the property type parameters, such as the apples and bananas constants. Or you can define properties and instantiators for a specific instantiation of the generic type, as shown by the AppleTree and BananaTree instantiators below.


Field Summary
static Property<Tree<Apple>,Iterable<? extends Apple>> apples
           
static Instantiator<Tree<Apple>> AppleTree
           
static Property<Tree<Banana>,Iterable<? extends Banana>> bananas
           
static Instantiator<Tree<Banana>> BananaTree
           
 
Constructor Summary
TreeMaker()
           
 
Method Summary
static
<F extends Fruit>
Property<Tree<F>,Iterable<? extends F>>
fruit()
           
static
<F extends Fruit>
Instantiator<Tree<F>>
Tree()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AppleTree

public static final Instantiator<Tree<Apple>> AppleTree

apples

public static final Property<Tree<Apple>,Iterable<? extends Apple>> apples

BananaTree

public static final Instantiator<Tree<Banana>> BananaTree

bananas

public static final Property<Tree<Banana>,Iterable<? extends Banana>> bananas
Constructor Detail

TreeMaker

public TreeMaker()
Method Detail

fruit

public static <F extends Fruit> Property<Tree<F>,Iterable<? extends F>> fruit()

Tree

public static <F extends Fruit> Instantiator<Tree<F>> Tree()


Copyright © 2010. All Rights Reserved.