Results 1 to 4 of 4

Thread: How to set default Java parameter values

  1. #1
    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?

  2. #2
    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.

  3. #3
    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.

  4. #4
    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.

Similar Threads

  1. W32 registry values are not getting matched by the default values
    By Angrzej in forum Networking & Security
    Replies: 5
    Last Post: 19-05-2011, 12:23 PM
  2. Replies: 5
    Last Post: 01-09-2010, 10:43 AM
  3. How to give a C# parameter a default value?
    By Migueel in forum Software Development
    Replies: 4
    Last Post: 10-02-2010, 10:21 PM
  4. C:/PROGRA~1\Java\jre6\bin\ssvagent.exe parameter is incorrect
    By Baazigar in forum Operating Systems
    Replies: 7
    Last Post: 15-11-2009, 12:26 AM
  5. Set default values for new DataRows in Ado.Net
    By Jateen in forum Software Development
    Replies: 3
    Last Post: 26-01-2009, 04:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,559,442.23121 seconds with 16 queries