alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (DynamicDispatch.java-notyet)

This example Scala source code file (DynamicDispatch.java-notyet) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

dynamicdispatch, dynamicdispatch, methodhandle, methodhandle, object, object

The Scala DynamicDispatch.java-notyet source code

package scala.runtime;

import java.dyn.CallSite;
import java.dyn.MethodHandle;

/**
 * This class resolves calls through refinement types. The
 * bootstrap method is called when an invokedynamic is found
 * by the Java VM.
 * 
 * Note: Requires Java 7 with invoke dynamic support (see JSR 292)
 *
 * @author Iulian Dragos
 * @see JSR292
 */
public class DynamicDispatch {

    /**
     * Resolve an invoke dynamic in Scala code. invokedynamic calls appear
     * when a method defined by a refinement type is called. It is resolved
     * by looking up a method with the same name and types in the receiver
     * object. It is guaranteed by the type checker that such a method 
     * exists.
     *
     * The current implementation is not correct, a call site being 
     * always bootstrapped to a method handle. A bound call site should be
     * guarded by a test on the receiver type. Such code should either
     * be generated by the compiler, or by this bootstrap method using
     * one of the code combinators provided in java.dyn.*. 
     *
     * ATM, they are not yet available in the JVM.
     */
    public static Object bootstrapInvokeDynamic(CallSite cs, Object... args) {
        println(cs);
        
        MethodHandle mh = MethodHandles.findVirtual(cs.callerClass(),
                                                    cs.name(),
                                                    cs.type());
        cs.setTarget(mh);
        return mh(args);
    }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala DynamicDispatch.java-notyet source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.