About 177,000 results
Open links in new tab
  1. How do I use optional parameters in Java? - Stack Overflow

    Jun 8, 2009 · Update: Java 8 includes the class java.util.Optional out-of-the-box, so there is no need to use guava for this particular reason in Java 8. The method name is a bit different though. The method name is a bit different though.

  2. calling method with Optional parameter in Java 8

    Nov 4, 2018 · Optional is a class and in Java you must pass the exact number of parameters to a method just like it is defined. The only exception is when you put ... after the class object name in the method declaration. public String test (String X, String... Y) { } Which makes the second parameter be either zero or more.

  3. Does Java support default parameter values? - Stack Overflow

    "A closure is a function that refers to a free variable in its lexical context." So here, in this case, closure is the returned function when operated on variable multiply and it has a free variable a that has the lexical context of the caller function. Return the multiply method or fix the default value for one of the parameters.

  4. How can I declare optional function parameters in JavaScript?

    Oct 9, 2012 · The special "array" arguments is available inside the function; it contains all the arguments, starting from index 0 to N - 1 (where N is the number of arguments passed). This is typically used to support an unknown number of optional parameters (of the same type); however, stating the expected arguments is preferred!

  5. java - How do I make List<string> as optional parameter ... - Stack ...

    Aug 16, 2021 · Note that (1) there's no point in assigning a new ArrayList<>() in your args initializer, as it will always be immediately discarded, and (2) it's typically best to make a defensive copy of items passed in this way, so this is likely better (since Java 10):

  6. Have multiple optional parameters in Java - Stack Overflow

    Java does support optional parameters in the form of var-args, but each method can only have 1 var-arg parameter and it must be the last in the list of parameters ( Varargs). Java supports overloading methods, and Java can distinguish between methods with …

  7. Why should Java 8's Optional not be used in arguments

    Aug 10, 2015 · Let's make something perfectly clear: in other languages, there is no general recommendation against the use of a Maybe type as a field type, a constructor parameter type, a method parameter type, or a function parameter type. So if you "shouldn't" use Optional as a parameter type in Java, the reason is specific to Optional, to Java, or to both.

  8. How to pass a function as a parameter in Java? [duplicate]

    Java 8 and above. Using Java 8+ lambda expressions, if you have a class or interface with only a single abstract method (sometimes called a SAM type), for example: public interface MyInterface { String doSomething(int param1, String param2); } then anywhere where MyInterface is used, you can substitute a lambda expression:

  9. arrays - java optional parameter in methods - Stack Overflow

    Feb 22, 2012 · No, Java doesn't support optional parameters. Another alternative to overloading (which doesn't make much sense for two parameters but does make sense for more) is to use a builder type which represents all the parameters - you can provide a constructor for the builder which contains the required parameters, and then a setter for each of the optional ones, making the setter return the builder ...

  10. In JavaScript, how can I create a function with an optional …

    Feb 9, 2010 · For when you've got an indeterminate number of optional arguments, you generally omit them from the function statement, and again a comment is polite: function myFunc(var1 /* , optional var2..varN */) { for (var i= 1; i<arguments.length; i++) ...