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
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)
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).
Code 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");
}