• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Method calling

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class vararg {
static void show(int ... a) {
System.out.println("varchar ---"+a[0]);
}

static void show(Object o,Object o1) {
System.out.println(o);
}
public static void main(String[] args) {
show(1,2);
}
}

please explain how the method show(Object o,Object o1 ) is called for show(1,2).
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Boxing will always be chosen over varargs...that's why show(Object o,Object o1 )is called.
widening beats boxing and varargs, and boxing beats varargs. In your case int is boxed to Integer...than widened to Object. Hope this helps you.
[ November 13, 2006: Message edited by: Valentin Mone ]
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sentil,
Remember the rule,
[*]boxing beats varargs
[*]widening beats varargs
So,varargs gets the chance only when there is no methods with matching parameters with the callee.
[ November 13, 2006: Message edited by: Sanjeev Kumar Singh ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic