T - the type of the object being decoratedpublic abstract class AbstractUnwrappable<T extends Unwrappable> extends Object implements Unwrappable
Unwrappable implementation.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractUnwrappable(T delegate)
Creates a new decorator with the specified delegate.
|
| Modifier and Type | Method and Description |
|---|---|
<U> U |
as(Class<U> type)
Unwraps this object into the object of the specified
type. |
protected <U extends T> |
delegate()
Returns the object being decorated.
|
String |
toString() |
protected AbstractUnwrappable(T delegate)
protected final <U extends T> U delegate()
public final <U> U as(Class<U> type)
Unwrappabletype.
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);
as in interface Unwrappabletype - the type of the object to returntype if found, or null if not found.Copyright © 2020 LeanCloud. All rights reserved.