Why isn't Math.max(double a, double b) variadic?

前端 未结 6 872
逝去的感伤
逝去的感伤 2021-01-12 23:33

Why isn\'t the implementation of Math.max a variadic function?

It could get implemented like this:

public class Main {
    public static double max(d         


        
6条回答
  •  攒了一身酷
    2021-01-13 00:13

    because its been there for longer than variadic functions exist in java (introduced in java 5) and there wasnt much demand to update it since, as you've just shown, its trivial to do yourself.

    also, there' s ahidden performance penalty involved in varargs methods as an array (double[]) will be created from your arguments behind the scenes

提交回复
热议问题