Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes formal parameter on functions in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "formal parameter on functions in java" Watch "formal parameter on functions in java" New topic
Author

formal parameter on functions in java

joe garcia
Greenhorn

Joined: Mar 01, 2010
Posts: 9
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

Joined: Sep 28, 2004
Posts: 20057
    
  44

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 44048
    
  33
Please tell the details; do you really get an Exception from "continue;" or a compiler error?
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: formal parameter on functions in java
 
It's not a secret anymore!