Package org.javacord.api.util
Interface SafeSpecializable<S>
-
- Type Parameters:
S- The base type of which subclasses are eligible to be cast.
- All Superinterfaces:
Specializable<S>
- All Known Subinterfaces:
Interaction,MessageComponentInteraction,SelectMenuInteraction
public interface SafeSpecializable<S> extends Specializable<S>
An object that may be specialized further and recast as a subclass. As opposed toSpecializable, it will not throw aNullPointerExceptionif the passed type is null.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default <T extends S>
Optional<T>as(Class<T> type)Get this instance as a desired subtype.
-
-
-
Method Detail
-
as
default <T extends S> Optional<T> as(Class<T> type)
Get this instance as a desired subtype.If the instance is not castable to the specified type, the
Optionalwill be empty.If the passed type is
null, an emptyOptionalwill be returned.- Specified by:
asin interfaceSpecializable<S>- Type Parameters:
T- The desired type.- Parameters:
type- The type as which to obtain this instance.- Returns:
- Returns an
Optionalof this instance if it could be cast, otherwise an empty result.
-
-