public class Bootstrap
extends java.lang.Object
The following example shows the definition of a bootstrap. The bootstrap is cached, so that it is invoked once.
The bootstrap class in placed in the apiTest
y
package, and it is named MiBootstrap
. The method to be called is callMethod
.
The Counter
class and the name of the method (concat)
are passed as additional parameters.
Bootstrap bootstrap = new Bootstrap("apiTest.MiBootstrap","callMethod", Counter.class, "concat");
The signature of the method in the bootstrap to be invoked is the following one:
public static CallSite callMethod(Lookup lookup, String name,MethodType type, Class> nameClass, String member)
The additional Counter
and concat
parameters are the two last arguments passed to
callMethod
The rest of parameters are mandatory for every bootstrap. These are the mandatory parameters:
The signature of the concat
method is the following one:
public static long concat(String cad1, String cad2);
The first operation before calling this method is getting its MethodHandle. Since concat
is static, we used the findStatic
method in lookup.
MethodHandle mh = lookup.findStatic(nameClass,member,type);
Once the MethodHandle is fetched, the CallSite can be created. We use a constant one in this example:
return new ConstantCallSite(mh);
Modifier and Type | Field and Description |
---|---|
private java.lang.Object[] |
args |
private Cache |
cache |
private java.lang.String |
classBootstrap |
private java.lang.String |
desc |
private org.objectweb.asm.Handle |
handle |
private java.lang.String |
methodBootstrap |
Constructor and Description |
---|
Bootstrap(Cache cache,
java.lang.String classBootstrap,
java.lang.String methodBootstrap,
java.lang.Object... args)
This constructor can be used to indicate whether or not the bootstrap must be stored in the cache.
|
Bootstrap(java.lang.String classBootstrap,
java.lang.String methodBootstrap,
java.lang.Object... args)
This constructor stores the bootstrap in the cache.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
checkTypes()
Checks that the types of the arguments to be passed to the bootstrap method are correct.
|
boolean |
equals(java.lang.Object obj) |
java.lang.Object[] |
getArgs()
Gets the additional parameters to be passed to the bootstrap.
|
Cache |
getCache()
Gets the value indicating whether or not the bootstrap should be cached.
|
private java.lang.String |
getDesc()
Gets the signature of the method in the bootstrap to be invoked.
|
org.objectweb.asm.Handle |
getHandle()
Gets the handle to be used in the bootstrap invocation.
|
int |
hashCode() |
private org.objectweb.asm.Handle handle
private final java.lang.Object[] args
private final Cache cache
private final java.lang.String classBootstrap
private final java.lang.String methodBootstrap
private final java.lang.String desc
public Bootstrap(Cache cache, java.lang.String classBootstrap, java.lang.String methodBootstrap, java.lang.Object... args)
cache
- Tells whether or not the bootstrap should be stored in the cache.classBootstrap
- Descriptor of the bootstrap class to be invoked.methodBootstrap
- Name of the method in the bootstrap to be invoked.args
- Additional parameters to be passed to the bootstrap. The types allowed are: Integer, Double, Float, Long, String, Class y Handle.public Bootstrap(java.lang.String classBootstrap, java.lang.String methodBootstrap, java.lang.Object... args)
classBootstrap
- Descriptor of the Bootstrap class to be invoked.methodBootstrap
- Name of the method in the bootstrap to be invoked.args
- Additional parameters to be passed to the bootstrap. The types allowed are: Integer, Double, Float, Long, String, Class y Handle.public java.lang.Object[] getArgs()
public org.objectweb.asm.Handle getHandle()
public Cache getCache()
private java.lang.String getDesc()
private boolean checkTypes()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object