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

varargs method for Math.max(...), min(...), addExact(...), multiplyExact(...) and all commutative and associative operations

XMLWordPrintable

      A DESCRIPTION OF THE REQUEST :
      Some operations in Math util class are commutative and associative, but only allow 2 parameters where one can expect those operations to work with any number of parameters.
      To make it easier to use those, it'd be useful to provide some varargs implementations of operations which are commutative and associative. Typical ones I have read use-case for today are Math.min(...) and Math.max(...) but it could extend to addExact(...) or multiplyExact(...) and maybe others.

      JUSTIFICATION :
      It would make it much easier to implement some comparisons between several collections/arrays.


      ---------- BEGIN SOURCE ----------
      int a = 0,
      int b = 1;
      int c = 0;
      assertEquals(1, Math.max(a, b, c));
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Workaround consists in chaining invocations of such operations.

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: