获得徽章 7
- /**
* Returns the value of the {@code long} argument;
* throwing an exception if the value overflows an {@code int}.
*
* @param value the long value
* @return the argument as an int
* @throws ArithmeticException if the {@code argument} overflows an int
* @since 1.8
*/
public static int toIntExact(long value) {
if ((int)value != value) {
throw new ArithmeticException("integer overflow");
}
return (int)value;
}展开1点赞 - 包含与聚合的区别
可以将“包含”关系类比为对象之间的组合关系,如汽车与轮胎,是一种must have,而“扩展”关系就是对象之间的聚合关系,如汽车与车载音响,是一种nice to have。
赞过评论1