Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by NavBot

...

Code Block
bgColor#FFCCCC
class OverloadedVarargs {
  private static void doSomething(boolean... bool) {
    System.out.print(""Number of arguments: "" + bool.length + "", Contents: "");

    for (boolean b : bool)
      System.out.print("[""[" + b + "]""]");
  } 
  private static void doSomething(boolean bool1, boolean bool2) {
    System.out.println(""Overloaded method invoked"");  
  }
  public static void main(String[] args) {
    doSomething(true, false);
  }
}

...

Code Block
bgColor#ccccff
class NotOverloadedVarargs {
  private static void doSomething1(boolean... bool) {
    System.out.print(""Number of arguments: "" + bool.length + "", Contents: "");

    for (boolean b : bool)
      System.out.print("[""[" + b + "]""]");
  } 
  private static void doSomething2(boolean bool1, boolean bool2) {
    System.out.println(""Overloaded method invoked"");  
  }
  public static void main(String[] args) {
    doSomething1(true, false);
  }
}

...

Wiki Markup
*EX1:* Sometimes, it is desirable to violate the ""do not overload varargs methods"" advice for performance reasons (avoiding the cost of creation of an array instance and its initialization on every invocation of a varargs method). \[[Bloch 08|AA. Java References#Bloch 08]\]

...

Wiki Markup
\[[Sun 06|AA. Java References#Sun 06]\] [varargs|http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html] 
\[[Bloch 08|AA. Java References#Bloch 08]\] Item 42: ""Use varargs judiciously""
\[[Steinberg 05|AA. Java References#Steinberg 05]\] ""Using the Varargs Language Feature""

...

DCL01-J. Use 'L', not 'l', to indicate a long value            03. Declarations and Initialization (DCL)            DCL03-J. Use meaningful symbolic constants to represent literal values in program logic