-1

I have a method similar to below with the same array type (Java), and I get the below warning from PMD when the checks are run.

How do I resolve it?

public static double calculateSum(Double[] numArray) {
    ....
}

PMD warning:

Consider using varargs for methods or constructors which take an array the last parameter.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Oasis001
  • 79
  • 2
  • 17
  • 4
    you can do as suggested, use varargs: `pubic static double calculateSum(Double... numArray)` or just ignore the warning (there must also be a way or *option* to turn it off) || despite I do not like the idea of doing that just because some framework/application suggested so; more important is to be sure what the method is expected to receive – user16320675 Oct 13 '22 at 16:52
  • Something seems to be missing in the supposed message from PMD, near *"an array the last parameter"*. – Peter Mortensen Dec 28 '22 at 16:16

1 Answers1

0

To call a function with a variable number of arguments, add three periods within the parameter declaration:

public static double calculateSum(Double... addendum) {
    double sum = 0;
    for (double num : addendum) {
        sum += num;   
    }
    return sum;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131