long to int java 8

Java
import static java.lang.Math.toIntExact;

long foo = 10L;
int bar = toIntExact(foo);
Source

Also in Java: