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 | Description |
---|---|---|
GuardedInvocation |
convertToType |
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 (sourceType)→targetType
, while the type of the guard is (sourceType)→boolean
. 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 method
invocation conversions
as those can be automatically applied by MethodHandle.asType(MethodType)
. An implementation can assume it is never requested to produce a converter for those conversions. If a language runtime needs to customize method invocation conversions, it should set an autoconversion strategy in the dynamic linker factory
instead.
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 if the method is invoked from within a LinkerServices.getWithLookup(Supplier, jdk.dynalink.SecureLookupSupplier)
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). 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 converter
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.dynalink/jdk/dynalink/linker/GuardingTypeConverterFactory.html