presto-main/src/main/java/io/prestosql/operator/scalar/TryCastFunction.java/TryCastFunction/specialize
class TryCastFunction:    @Override
    public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, Metadata metadata)
    {
        Type fromType = boundVariables.getTypeVariable("F");
        Type toType = boundVariables.getTypeVariable("T");

        Class<?> returnType = Primitives.wrap(toType.getJavaType());
        List<ArgumentProperty> argumentProperties;
        MethodHandle tryCastHandle;

        // the resulting method needs to return a boxed type
        ResolvedFunction resolvedFunction = metadata.getCoercion(fromType, toType);
        ScalarFunctionImplementation implementation = metadata.getScalarFunctionImplementation(resolvedFunction);
        argumentProperties = ImmutableList.of(implementation.getArgumentProperty(0));
        MethodHandle coercion = implementation.getMethodHandle();
        coercion = coercion.asType(methodType(returnType, coercion.type()));

        MethodHandle exceptionHandler = dropArguments(constant(returnType, null), 0, RuntimeException.class);
        tryCastHandle = catchException(coercion, RuntimeException.class, exceptionHandler);

        return new ScalarFunctionImplementation(true, argumentProperties, tryCastHandle);
    }