Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4940463

Java lacks a default method argument facility

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.2, 6
    • specification
    • x86
    • linux, windows_xp

      Name: rmT116609 Date: 10/20/2003


      A DESCRIPTION OF THE REQUEST :
      Java forces me to supply an argument for each method parameter.

      JUSTIFICATION :
      Lengthy method signatures often require convenience overloads that supply the requisite default values. These methods cut down on clutter and errors in the caller's code. Overriding them is a pain, however, and you can often end up with one additional method for each parameter.

      public void foo( boolean a)...



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      public void foo(boolean a = true, String b = "bar", Long c = 1, double d = 1.0)
      ACTUAL -
      Obviously this will not compile because Java does not allow default arguments.

      ---------- BEGIN SOURCE ----------
      Not applicable: language extension required to fix this.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      public void foo( boolean a, String b, Long c, double d)...
      public void foo( boolean a, String b, Long c)...
      public void foo( boolean a, String b)...

      Supply a convenience method for each permutation (or is that combination) of parameters.
      (Incident Review ID: 216646)
      ======================================================================

            abuckley Alex Buckley
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: