• 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

variable arguments in functions

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know if java provides for handling variable argument lists like 'C'?
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The concept in Java is called overloading. While Java doesn't permit 'default' agruements in the parameter list, you can effectivly do this with overloading.
Example:

Hope this helps
 
equisitive
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if you understand what I am asking. I was wondering if java has a way to handle variable arguments in method calls like C.
e.g.
printf has a signature:
const char *printf( const char *format, ... );
where '...' is a variable list of arguments where the number of variable arguments can not be known.
If I want to process a variable number of arguments of various types, in C/C++(not sure about other languages) I can declare a method like:
void foo( arg1, arg2, ... );
allowing me to process 2(arg1, arg2) to n arguments and process the n - 2 variable arguments in my method definition if I so choose. Does anyone know if Java provides for this?
Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic