@SuppressWarnings("unchecked")
    public static <T> Nullable<T> castIfAssignable(final Object val, final Class<T> targetType) {
        if (Primitives.isPrimitiveType(targetType)) {
            return val != null && Primitives.wrap(targetType).isAssignableFrom(val.getClass()) ? Nullable.of((T) val) : Nullable.<T> empty();
        }

        return val == null || targetType.isAssignableFrom(val.getClass()) ? Nullable.of((T) val) : Nullable.<T> empty();
    }
@ SuppressWarnings ( "unchecked" ) public static < T > Nullable < T > castIfAssignable ( final Object val , final Class < T > targetType ) { if ( Primitives . isPrimitiveType ( targetType ) ) { return val != null && Primitives . wrap ( targetType ) . isAssignableFrom ( val . getClass ( ) ) ? Nullable . of ( ( T ) val ) : Nullable . < T > empty ( ) ; } return val == null || targetType . isAssignableFrom ( val . getClass ( ) ) ? Nullable . of ( ( T ) val ) : Nullable . < T > empty ( ) ; }
Returns an empty <code>Nullable</code> if {@code val} is {@code null} while {@code targetType} is primitive or can not be assigned to {@code targetType}.
Please be aware that {@code null} can be assigned to any {@code Object} type except primitive types: {@code boolean/char/byte/short/int/long/double}.

@param val
@param targetType
@return