什么是Java中最惯用的方法来验证,从铸造long到int不会丢失任何信息?
这是我目前的实现:
public static int safeLongToInt(long l) { int i = (int)l; if ((long)i != l) { throw new IllegalArgumentException(l + " cannot be cast to int without changing its value."); } return i;}
相似问题