Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Program of Autoboxing where widening beats varargs

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 268
    Comment on it

    Widening

    Widening in Java can be defined as converting a variable of a particular type into wider type. E.g: short is converted int primitive type.

    varargs

    varangs is variable arguments. varangs as name suggest allows a method to have 0 or mutiple argument.

    Syntax of varargs:

    return_type method_name(data_type... variableName){} 

    Proram of Autoboxing where widening beats varargs:

    class Boxing1
    {  
      static void m(int i1, int i2)  //overloaded method with int primitive type
      {
       System.out.println("int int");
      }  
       static void m(Integer... i)  overloaded method with varangs
      {
       System.out.println("Integer...");
      }  
      
      public static void main(String args[])
      {  
       short s1=30,s2=40;  
       m(s1,s2);  
     }   
    }  

    Output:

    int int

    In above program from main when overloaded method m is called with two short values as parameter then function m with int primitive type is called because short variables type is automatically converted to wider type i.e int. Therefore widening beats varargs which was parameter of overloaded method m in which 0 or multiple Integer wrapper types can be passed.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: