Bootstrap method question
Howard Lovatt
howard.lovatt at gmail.com
Sat Jun 12 01:03:29 PDT 2010
This is probably my mistake, but I thought it worth checking anyway!
I am playing around with multiple dispatch in the MLVM, in particular.
public class Cost {
/* Written by PEC! */ static {
final MethodHandle bootstrap = MethodHandles.lookup().findStatic(
CostCalculatorDispatcher.class,
"cost",
Dispatchers.bootstrapType );
Linkage.registerBootstrapMethod( Cost.class, bootstrap );
}
public static void main( final String[] notUsed ) {
final List<Item> shoppingCart = new ArrayList<Item>();
shoppingCart.add( new Book( 20, 0.5 ) );
shoppingCart.add( new CD( 25 ) );
System.out.println( "cost = " + cost( shoppingCart ) );
}
public static double cost( final List<Item> shoppingCart ) {
final CostCalculator price = new Price();
final CostCalculator postage = new Postage();
double cost = 0;
for ( final Item item : shoppingCart ) {
try { /* Written by PEC! */
cost += InvokeDynamic.<double>cost( price, item );
} catch ( Throwable e ) {
throw new MultipleDispatchException( e );
}
try { /* Written by PEC! */
cost += InvokeDynamic.<double>cost( postage, item );
} catch ( Throwable e ) {
throw new MultipleDispatchException( e );
}
}
return cost;
}
}
The bootstrap method gets called, but its type argument is:
(invokedynamicmultipledispatch.CostCalculator,invokedynamicmultipledispatch.Item)double
IE the static types, I was expecting the dynamic types:
(invokedynamicmultipledispatch.Price,invokedynamicmultipledispatch.Book)double
etc.
What am I doing wrong?
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/mlvm-dev/attachments/20100612/6126bcb1/attachment.html
More information about the mlvm-dev
mailing list