Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Call with a different signature

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Call with a different signature

    I am calling a methode with seven params from a class, but when i am executing the code.
    it is throwing an exception that no such methode error with six params .
    it sreally strange for me. is it possible in java that a methode get called in a manner which is not there in the code. and fourth params is missing. even if the 4th param is null it should call it with seven params.
    Please reply if you had a similar issue . thanks in advance


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Call with a different signature

    Please post a short snipped of the code and associated method to provide some context. If you have a method with 7 params, you must call that method with 7 parameters (the exception being for variable length method (...) statements)

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Call with a different signature

    putting null as a parameter counts as a parameter (it's like saying there are 0 apples. Still a valid number, even if there are none).

    In Java you must call a method exactly as it's specified. There's no such thing as default parameters. The one exception is the use of the ... token. This is a shorthand method of converting a list of parameters into an array (note that this can only be done once/method definition, and must be the last parameter).

    If you want multiple methods which do the same thing but with multiple parameters, overload the method with the most parameters and have the other ones pass that method "default" values (true default values for parameters is not allowed in Java).

    public static void foo(int a, int b, int c, String d)
    {
        // do stuff
    }
     
    public static void foo(int a)
    {
        // call foo with default b=0, c=0, d="hello"
        foo(a, 0, 0, "hello");
    }

Similar Threads

  1. [SOLVED] Trying to call web service (and failing)
    By jamesruk21 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 15th, 2011, 12:35 PM
  2. call win32 api from java
    By bapu in forum Java Native Interface
    Replies: 3
    Last Post: November 7th, 2010, 09:42 AM
  3. El Gamal signature -Handle big integer
    By miotvsingtel in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 9th, 2010, 12:05 PM
  4. JSP freezes after AJAX call !!
    By java_freek in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: April 16th, 2010, 10:31 AM
  5. Under Windows OS, how to call *.EXE produced in Linux OS?
    By tony_lincoln in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 19th, 2010, 12:51 AM