public interface GuardingTypeConverterFactory
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 |
---|---|
GuardedInvocation |
convertToType(Class<?> sourceType,
Class<?> targetType,
Supplier<MethodHandles.Lookup> lookupSupplier)
Returns a guarded type conversion that receives a value of the specified
source type and returns a value converted to the specified target type.
|
GuardedInvocation convertToType(Class<?> sourceType, Class<?> targetType, Supplier<MethodHandles.Lookup> lookupSupplier) throws Exception
The type of the invocation is targetType(sourceType)
, while the
type of the guard is boolean(sourceType)
. You are allowed to
return unconditional invocations (with no guard) if the source type is
specific to your runtime and your runtime only.
Note that this method will never be invoked for type conversions
allowed by the JLS 5.3 "Method Invocation Conversion", see
TypeUtilities.isMethodInvocationConvertible(Class, Class)
for
details. An implementation can assume it is never requested to produce a
converter for these conversions.
Dynalink is at liberty to either cache some of the returned converters or to repeatedly request the converter factory to create the same conversion.
sourceType
- source typetargetType
- the target type.lookupSupplier
- 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 invokedynamic
instruction the
supplier will return the lookup passed to the bootstrap method, otherwise
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). Invoking the Supplier.get()
method on the passed supplier will be subject to the same security checks
as SecureLookupSupplier.getLookup()
. An implementation should avoid
retrieving the lookup if it is not needed so as to avoid the expense of
AccessController.doPrivileged
call.Exception
- if there was an error during creation of the converterLinkerServices.getWithLookup(Supplier, SecureLookupSupplier)
Copyright © 2015, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-internal+0-2016-03-31-172659.buildd.src