Annotation Type Super


  • @Documented
    @Retention(RUNTIME)
    @Target(PARAMETER)
    public @interface Super
    Parameters that are annotated with this annotation are assigned an instance of an auxiliary proxy type that allows calling any super methods of the instrumented type where the parameter type must be a super type of the instrumented type. The proxy type will be a direct subclass of the parameter's type such as for example a specific interface.

     

    Obviously, the proxy type must be instantiated before it is assigned to the intercepting method's parameter. For this purpose, two strategies are available which can be specified by setting the strategy() parameter which can be assigned:
    1. Super.Instantiation.CONSTRUCTOR: A constructor call is made where constructorParameters() determines the constructor's signature. Any constructor parameter is assigned the parameter's default value when the constructor is called. Calling the default constructor is the preconfigured strategy.
    2. Super.Instantiation.UNSAFE: The proxy is created by making use of Java's ReflectionFactory which is however not a public API which is why it should be used with care. No constructor is called when this strategy is used. If this option is set, the constructorParameters() parameter is ignored.
    Note that when for example intercepting a type Foo that implements some interface Bar, the proxy type will only implement Bar and therefore extend Object what allows for calling the default constructor on the proxy. This implies that an interception by some method qux(@Super Baz baz, @Super Bar bar) would cause the creation of two super call proxies, one extending Baz, the other extending Bar, give that both types are super types of Foo.

     

    As an exception, no method calls to Object.finalize() are delegated by calling this method on the super-call proxy by default. If this is absolutely necessary, this can however be enabled by setting ignoreFinalizer() to false.

     

    If a method parameter is not a super type of the instrumented type, the method with the parameter that is annotated by #Super is not considered a possible delegation target.
    See Also:
    MethodDelegation, TargetMethodAnnotationDrivenBinder
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.Class<?>[] constructorParameters
      Defines the parameter types of the constructor to be called for the created super-call proxy type.
      boolean ignoreFinalizer
      If true, the proxy type will not implement super calls to Object.finalize() or any overridden methods.
      java.lang.Class<?> proxyType
      Determines the type that is implemented by the proxy.
      boolean serializableProxy
      Determines if the generated proxy should be Serializable.
      Super.Instantiation strategy
      Determines how the supercall proxy type is instantiated.
    • Element Detail

      • strategy

        Super.Instantiation strategy
        Determines how the supercall proxy type is instantiated.
        Returns:
        The instantiation strategy for this proxy.
        Default:
        net.bytebuddy.implementation.bind.annotation.Super.Instantiation.CONSTRUCTOR
      • ignoreFinalizer

        boolean ignoreFinalizer
        If true, the proxy type will not implement super calls to Object.finalize() or any overridden methods.
        Returns:
        false if finalizer methods should be considered for super-call proxy type delegation.
        Default:
        true
      • serializableProxy

        boolean serializableProxy
        Determines if the generated proxy should be Serializable. If the annotated type already is serializable, such an explicit specification is not required.
        Returns:
        true if the generated proxy should be Serializable.
        Default:
        false
      • constructorParameters

        java.lang.Class<?>[] constructorParameters
        Defines the parameter types of the constructor to be called for the created super-call proxy type.
        Returns:
        The parameter types of the constructor to be called.
        Default:
        {}
      • proxyType

        java.lang.Class<?> proxyType
        Determines the type that is implemented by the proxy. When this value is set to its default value void, the proxy is created as an instance of the parameter's type. When it is set to TargetType, it is created as an instance of the generated class. Otherwise, the proxy type is set to the given value.
        Returns:
        The type of the proxy or an indicator type, i.e. void or TargetType.
        Default:
        void.class