Class AbstractUnwrappable<T extends Unwrappable>

java.lang.Object
com.linecorp.armeria.common.util.AbstractUnwrappable<T>
Type Parameters:
T - the type of the object being decorated
All Implemented Interfaces:
Unwrappable
Direct Known Subclasses:
BackoffWrapper, DecoratingClient, DecoratingService, UserClient

public abstract class AbstractUnwrappable<T extends Unwrappable>
extends Object
implements Unwrappable
Skeletal Unwrappable implementation.
  • Constructor Details

    • AbstractUnwrappable

      protected AbstractUnwrappable​(T delegate)
      Creates a new decorator with the specified delegate.
  • Method Details

    • delegate

      protected final <U extends T> U delegate()
      Returns the object being decorated.
    • as

      public final <U> U as​(Class<U> type)
      Description copied from interface: Unwrappable
      Unwraps this object into the object of the specified type. Use this method instead of an explicit downcast. For example:
      
       class Foo {}
      
       class Bar<T> extends AbstractWrapper<T> {
           Bar(T delegate) {
               super(delegate);
           }
       }
      
       class Qux<T> extends AbstractWrapper<T> {
           Qux(T delegate) {
               super(delegate);
           }
       }
      
       Qux qux = new Qux(new Bar(new Foo()));
       Foo foo = qux.as(Foo.class);
       Bar bar = qux.as(Bar.class);
       
      Specified by:
      as in interface Unwrappable
      Parameters:
      type - the type of the object to return
      Returns:
      the object of the specified type if found, or null if not found.
    • toString

      public String toString()
      Overrides:
      toString in class Object