Class Cast

java.lang.Object
dev.satyrn.papermc.api.util.v1.Cast

public final class Cast extends Object
Utility for safe-casting between objects.
Since:
1.6.0
Author:
Isabel Maskrey
  • Method Details

    • as

      @NotNull public static <T> @NotNull Optional<T> as(@NotNull @NotNull Class<T> asClass, @Nullable @Nullable Object object)
      Safe-casts an object to another type.
      Type Parameters:
      T - The type that the object will be cast to.
      Parameters:
      asClass - The class to cast to.
      object - The object to cast.
      Returns:
      An optional of T where the result is only present if the cast succeeded.
      Since:
      1.6.0
    • as

      @NotNull public static <T> @NotNull Optional<T> as(@Nullable @Nullable Object object)
      Performs an unsafe cast from an object to a generic type.
      Type Parameters:
      T - The type that the object will be cast to.
      Parameters:
      object - The object to cast.
      Returns:
      An optional of T where the result is only present if the cast succeeds.
      Since:
      1.9.1