Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does this happen?  RSS feed

 
Nikhil Sun
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a small program where the following line is used:

Integer rovX = Integer.parseInt(str1.substring(0,1));

where str1 is any string.

If the Integer class' parseInt(String) method returns the primitive int how does code with above line compile and run fine?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works due to a feature introduced in Java 5 called autoboxing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!