Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-03-2009
Member
 
Join Date: Feb 2009
Posts: 105
How to set default Java parameter values

Some time ago I read about default parameter values, like


Code:
public blah(int a=0, int b=2) { ... }

or atleast I thought I did, cause it wont work when I try it out.
Ive searched google, but cant find anything.

Am I doing it wrong, or is this not supported in java?
Reply With Quote
  #2  
Old 03-03-2009
Member
 
Join Date: Dec 2008
Posts: 161
Re: How to set default Java parameter values

I've been coding Java for several years and it is little difficult for understand what you exactly want.

What default parameters are you looking for? Java and the JVMs seem to have lots of defaults in them; for example, if you don't specify a memory parameter, a default amount of memory is assumed.

I'm not sure what you're hoping to find either; it's not that often that a company will write documentation about why they DIDN'T do something. Documentation usually covers things that were done, not omitted.

I suppose you *might* find something like interviews with top designers at Sun explaining why they took a certain path and chose not to take some other path that could touch on whatever you're after. Sun has some chat transcripts at java.sun.com so if you look through those you might find what you want.

But without knowing more clearly what you want, I can't suggest more than that.
Reply With Quote
  #3  
Old 03-03-2009
Member
 
Join Date: Jan 2006
Posts: 211
Re: How to set default Java parameter values

Creating a parameter

To create a parameter
  1. Drag the Parameter element from the Model page of the Palette view onto the diagram of active object class.
  2. Go to the General page of the Properties view.
  3. Type the name of the parameter in the Name edit box. The name is used to identify and access the parameter.
  4. Specify the type of the parameter. You can choose one of the most-used types (int, double, boolean, String) using the corresponding option from the Type buttons group. However, if you need to define a parameter of some other Java class, choose Other option and type the required class name in the edit box to the right.
  5. If needed, you can specify the parameter's default value in the Default value edit box. The value of the parameter can be changed afterwards during the model simulation. If default value is not specified, Java rules apply, for example a parameter of type double is set to 0, a parameter of type boolean is false.
Reply With Quote
  #4  
Old 03-03-2009
Member
 
Join Date: Dec 2008
Posts: 161
Re: How to set default Java parameter values

Generally speaking, a function should never be called if there's no data to pass to it. If you find yourself in such a situation, chances are you've planned something incorrectly. Those functions which conceivably require a default value are likely poorly implemented, and can probably be broken up into at least two functions - one which requires data, and one which doesn't. If it can't, then the mistake is elsewhere.

Of course, you can always specify a fallback value, either through a class field, or within the body of the method, but it's not always applicable. Best bet (in Java, at least) is to go back and rethink what you're doing.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to set default Java parameter values"
Thread Thread Starter Forum Replies Last Post
W32 registry values are not getting matched by the default values Angrzej Networking & Security 5 19-05-2011 12:23 PM
Outlook 2003 Error:"Could not complete the operation. One or more parameter values are not valid" AAROON Windows Software 5 01-09-2010 10:43 AM
How to give a C# parameter a default value? Migueel Software Development 4 10-02-2010 10:21 PM
C:/PROGRA~1\Java\jre6\bin\ssvagent.exe parameter is incorrect Baazigar Operating Systems 7 15-11-2009 12:26 AM
Set default values for new DataRows in Ado.Net Jateen Software Development 3 26-01-2009 04:46 PM


All times are GMT +5.5. The time now is 12:17 PM.