What is the differences between Int and Integer in Scala?

“What are the differences between Integer and Int?”

Integer is just an alias for java.lang.Integer. Int is the Scala integer with the extra capabilities.

Looking in Predef.scala you can see this the alias:

 /** @deprecated use <code>java.lang.Integer</code> instead */
  @deprecated type Integer = java.lang.Integer

However, there is an implicit conversion from Int to java.lang.Integer if you need it, meaning that you can use Int in methods that take an Integer.

As to why it is deprecated, I can only presume it was to avoid any confusion over which kind of integer you were working with.

Leave a Comment