You are getting confused between casting and boxing.
When int gets converted to Integer - it's called boxing and revrese process is called unboxing.
JAVA supports autoboxing, which means your primitive will eb automatically converted to it's wrapper class when required & vice versa.
E.g int -> Integer, long -> Long etc.
Java also supports casting among primitives which means int primitive can be implicitly casted to long primitive.
What you are trying to achieve is a combination of above to operations. You want to convert int to Long which will require 2 steps, which may be achieved in 2 different ways(let's assume for a moment following are possible):
Way 1:
- casting int to long
- Boxing long to Long
Way 2:
- boxing int to Integer
- casting Integer to Long
Since there is no clarity which way to choose, therefore JAVA does not allow allow any of the 2 step process as an automatic conversion.