Java autoboxing unboxing in method calling and returning

Introduction

Autoboxing happens when a primitive type must be converted into an object.

Auto-unboxing happens when an object must be converted into a primitive type.

Autoboxing/unboxing might happen in an argument passed, or a value returning.


public class Main { 
  static int m(Integer v) { 
    return v ; // auto-unbox to int 
  }  /*from  ww  w  . j a va  2s . c om*/
 
  public static void main(String args[]) {     
    Integer iOb = m(100);  
 
    System.out.println(iOb); 
  } 
}



PreviousNext

Related