Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does Java offer any support for optional/default parameters?

 
Michael Arnett
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I was wondering if Java had any method for supporting optional parameters? I know about the ability to overload, but is there any default value methodology, outright optional parameter syntax, etc.? Thanks in advance!
-MLA
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only overloading. Java didn't have default parameters like VB and some other languages. You can mimic it using :


------------------
Hope This Helps
Carl Trusiak, SCJP2
[This message has been edited by Carl Trusiak (edited May 25, 2001).]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you also mimic this by making one of the parameters an array of objects? This way you can supply any number of parameters.
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes , if you don't wish to pass an array to that method you can pass a null to it which your method would handle depedning on logic of it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic