Class Cast


  • public final class Cast
    extends java.lang.Object
    Utility class for type casts.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Cast()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T unchecked​(java.lang.Object value)
      Performs an unchecked cast.
      • Methods inherited from class java.lang.Object

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

      • Cast

        private Cast()
    • Method Detail

      • unchecked

        public static <T> T unchecked​(java.lang.Object value)
        Performs an unchecked cast.

        For example this code snipped:

         @SuppressWarnings("unchecked") 
         Img<T> image = (Img<T>) ArrayImgs.ints(100, 100); 
         
        Can be rewritten as:
         Img<T> image = Casts.unchecked( ArrayImgs.ints(100, 100) );
         
        It's possible to explicitly specify the return type:
         Img<T> image = Casts.<Img<T>>unchecked( ArrayImgs.ints(100, 100) );
         
        Throws:
        java.lang.ClassCastException - during runtime, if the cast is not possible.