GuardingDynamicLinker
implementations to provide language-specific type conversion capabilities.
Note that if you implement this interface, you will very likely want to
implement ConversionComparator interface too, as your additional
language-specific conversions, in absence of a strategy for prioritizing
these conversions, will cause more ambiguity for BeansLinker in
selecting the correct overload when trying to link to an overloaded Java
method.
| Modifier and Type | Method and Description |
|---|---|
| public GuardedInvocation | Returns: a guarded invocation that can take an object (if it passes guard) and return another object that is its representation coerced into the target type. In case the factory is certain it is unable to handle a conversion, it can return null. In case the factory is certain that it can always handle the conversion, it can return an unconditional invocation (one whose guard is null).source type sourceType, Class<?> the target type. targetType, Supplier<MethodHandles.a supplier for retrieving the lookup of the class
on whose behalf a type converter is requested. When a converter is
requested as part of linking an lookupSupplierinvokedynamic instruction the
supplier will return the lookup passed to the bootstrap method, otherwise
if the method is invoked from within a
LinkerServices#getWithLookup(Supplier, jdk.
it will delegate to the secure lookup supplier. In any other case,
it will return the public lookup. A typical case where the lookup might
be needed is when the converter creates a Java adapter class on the fly
(e.g. to convert some object from the dynamic language into a Java
interface for interoperability).Returns a guarded type conversion that receives a value of the specified source type and returns a value converted to the specified target type. |
| convertToType | back to summary |
|---|---|
| public GuardedInvocation convertToType(Class<?> sourceType, Class<?> targetType, Supplier<MethodHandles. Returns a guarded type conversion that receives a value of the specified source type and returns a value converted to the specified target type. Value types can be either primitives or reference types, including interfaces, so you can even provide converters for converting your language's objects to Java interfaces and classes by generating adapters for them.
The type of the invocation is Note that this method will never be invoked for
Dynalink is at liberty to either cache some of the returned converters or to repeatedly request the converter factory to create the same conversion.
| |