0

I've just started learning Java and in every learning material, I see that for new method incoming parameters should be defined. If method doesn't use anything anyway it's defined like (String[] args). It's Ok for me. However I've seen one example with definition like in subject:

main(String... ignored)

I understand what it means but I've never seen any description for such kind of syntax. What does "..." and "ignored" means from JVM point of view and how I could use this in other situations? Thanks!

Some guy
  • 1,210
  • 1
  • 17
  • 39
  • 1
    `ignored` is just a variable name. Here is the documentation details for [Arbitrary Number of arguments](https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html) – nIcE cOw Jul 23 '15 at 15:27
  • 1
    `ignored` is simply the chosen name for the method's parameter, nothing more or nothing less, but it indicates to others that the author of the method is likely not going to use the parameter values within the method. – Hovercraft Full Of Eels Jul 23 '15 at 15:27

1 Answers1

0

In a method definition the... Is a shorthand meaning array or single of a certain type ie. If you deline the following method

public static void Printer(String... msg) {

  for (String s: msg) {
     system.out.Print( s) ;
  }

}

You can call the method with either a parameter of String or String []

Eg.

String single = "hello world";
String[] arr = {"word","moreWords"};

Printer(single) ;
Printer(are);

Also the name ignored is just what the variable will be called when passed into the method. It could just as well have been called 'mySuperDooperVariableName'

Jacques Ramsden
  • 801
  • 5
  • 20