The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
May 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Optional Arguments

Posted by Eugene Kaganovich on May 03, 2000 at 6:48 PM

> hi,
> Can we create a method in java having some arguments as optional?
> If possible how?.Your explanation with source code
> will be appreciated.
> Thank you

You cannot directly specify an optional argument in the method signature. However, you can overload the method with two different signatures, that will effectively do the same thing.

For example:

public void foo(int iVar) {
foo(iVar, true);

public void foo(int iVar, boolean flag) {
// do something


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us