Integer i = theLong != null ? theLong.intValue() : null;
or if you don't need to worry about null:
// auto-unboxing does not go from Long to int directly, so
Integer i = (int) (long) theLong;
And in both situations, you might run into overflows (because a Long can store a wider range than an Integer).
Java 8 has a helper method that checks for overflow (you get an exception in that case):
Integer i = theLong == null ? null : Math.toIntExact(theLong);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…