Package com.linecorp.armeria.common.util
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
,ConnectionPoolListenerWrapper
,DecoratingClient
,DecoratingClientFactory
,DecoratingService
,RequestContextStorageWrapper
,UserClient
public abstract class AbstractUnwrappable<T extends Unwrappable> extends Object implements Unwrappable
Skeletal
Unwrappable
implementation.-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractUnwrappable(T delegate)
Creates a new decorator with the specified delegate. -
Method Summary
-
Constructor Details
-
AbstractUnwrappable
Creates a new decorator with the specified delegate.
-
-
Method Details
-
as
Description copied from interface:Unwrappable
Unwraps this object into the object of the specifiedtype
. 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 interfaceUnwrappable
- Parameters:
type
- the type of the object to return- Returns:
- the object of the specified
type
if found, ornull
if not found.
-
unwrap
Description copied from interface:Unwrappable
Unwraps this object and returns the object being decorated. If thisUnwrappable
is the innermost object, this method returns itself. For example:class Foo implements Unwrappable {} class Bar<T extends Unwrappable> extends AbstractUnwrappable<T> { Bar(T delegate) { super(delegate); } } class Qux<T extends Unwrappable> extends AbstractUnwrappable<T> { Qux(T delegate) { super(delegate); } } Foo foo = new Foo(); assert foo.unwrap() == foo; Bar<Foo> bar = new Bar<>(foo); assert bar.unwrap() == foo; Qux<Bar<Foo>> qux = new Qux<>(bar); assert qux.unwrap() == bar; assert qux.unwrap().unwrap() == foo;
- Specified by:
unwrap
in interfaceUnwrappable
-
toString
-