Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

formal parameter on functions in java  RSS feed

 
joe garcia
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
questions

the function is like this


if we call the functionName("stringvalue"); it is fine

but if we were to call functionName() with no paramater , i still get an exception even though I have if(param1 == null) continue;

in this case i thought we are passing nothing ( which we are passing null ) and i want that to be OK because I might not really need String to be passed in in parameter

similar code in php would be


which say that param1 is optional.

i want the same thing on java .


thanks for the help
 
Henry Wong
author
Sheriff
Posts: 22845
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't support default arguments (unless you want to count var-arg as such, but I digress). You will need to overload the method with a no-arg version, that calls the original version with null.

Henry
 
Campbell Ritchie
Sheriff
Posts: 53769
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell the details; do you really get an Exception from "continue;" or a compiler error?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!