Class Cast

java.lang.Object
net.imglib2.util.Cast

public final class Cast extends Object
Utility class for type casts.
  • Constructor Details

    • Cast

      private Cast()
  • Method Details

    • unchecked

      public static <T> T unchecked(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:
      ClassCastException - during runtime, if the cast is not possible.