Class Cast


  • public class Cast
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T cast​(java.lang.Object x)
      Casts the given object to type T.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • cast

        public static <T> T cast​(java.lang.Object x)
        Casts the given object to type T. This static method can be used to avoid "unchecked cast" warnings. Note that a runtime exception is still thrown if the cast is not valid. However, using this method eliminates the use of the @@SupressWarnings annotation, which obfuscates any valid warnings. Note that this method should be used in combination with assertions to assert the right type!
        Type Parameters:
        T - The type to cast to.
        Parameters:
        x - the object to cast
        Returns:
        (T) x;