What is autoboxing in Java?

Java 8Object Oriented ProgrammingProgramming

Autoboxing refers to the automatic conversion of a primitive type variable to its corresponding wrapper class object. The compiler automatically handles the conversion when a primitive value is −

Passed as an argument to a function which is expecting a wrapper class object. assigned to a variable of the type of wrapper class.

Example

Live Demo

public class Test{
   public static void main(String[] args) {
      int num = 122;
      Integer dat = num;
      System.out.println(dat);
   }
}

Output

122
raja
Ali
Published on 10-Jan-2018 06:03:51
Advertisements