• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formal parameter on functions in java

 
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
Marshal
Pie
Posts: 21490
84
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
Pie
Posts: 50171
79
  • 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