Interface Conversion<S,​T>

    • Method Summary

      Modifier and Type Method Description
      T apply​(S value)
      Applies the conversion
      default Optional<Type<? extends T>> resolveReturnType​(Type<? extends S> source, Type<? extends T> target)
      Helps the compiler to resolve the return type for a possible conversion.
    • Method Detail

      • resolveReturnType

        default Optional<Type<? extends T>> resolveReturnType​(Type<? extends S> source,
                                                              Type<? extends T> target)
        Helps the compiler to resolve the return type for a possible conversion. Note that this method is always called with a concrete source type (either a non-template, or a specialised one) and a target template type which can be either a non-template or an unbounded template.

        This method is invoked by the compiler due to one of the following conditions:

        • The source type is a specialized template, so the compiler needs to ensure that it can be effectively casted
        • The target type is a unbounded template, so the compiler needs to resolve a specialisation for it

        The default implementation will handle the aforementioned cases as follows:

        • When the source is a specialised template and the target is an unbounded template, specialise the target using the same parameters as the source
        • No match in any other case
        Parameters:
        source - The source type. It is ensured to be a concrete type
        target - The target type. Could be either a non-template or an unbounded template
        Returns:
        The specialized return type, or empty when no match
      • apply

        T apply​(S value)
        Applies the conversion
        Parameters:
        value - Source value
        Returns:
        Converted value