Class Cast


  • @Internal
    public class Cast
    extends Object
    This is a way for us to declare explicitly that we know something that the compiler doesn't and pinky-swear that the value we have really is of the inferred return type.

    This utility method should really be available from the JDK itself, but in the meantime...

    • Method Detail

      • unsafeCast

        public static <T> T unsafeCast​(@Nullable
                                       Object obj)
        Infer the expected type from the context and implicitly cast the provided value to match it.
        Type Parameters:
        T - the type required, as inferred by the compiler
        Parameters:
        obj - the object that we expect to be of the needed type
        Returns:
        (T) obj
        Throws:
        ClassCastException - at runtime if the given object is not of the expected type