public interface Unwrappable
| Modifier and Type | Method and Description |
|---|---|
default <T> T |
as(Class<T> type)
Unwraps this object into the object of the specified
type. |
default <T> T as(Class<T> type)
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);
type - the type of the object to returntype if found, or null if not found.Copyright © 2020 LeanCloud. All rights reserved.