public static int safeCast(long num) {

        if (num < Integer.MIN_VALUE || num > Integer.MAX_VALUE) {
            throw new ArithmeticException("Out of range: " + num);
        } else {
            return (int) num;
        }

    }
public static int safeCast ( long num ) { if ( num < Integer . MIN_VALUE || num > Integer . MAX_VALUE ) { throw new ArithmeticException ( "Out of range: " + num ) ; } else { return ( int ) num ; } }
/*[deutsch]
<p>Macht einen sicheren TypeCast auf ein int-Primitive. </p>

@param   num     long-primitive
@return  int as type-cast
@throws  ArithmeticException if int-range overflows