Formatting multiple arguments passed to a function in Java

后端 未结 6 1027
广开言路
广开言路 2021-02-13 21:18

Often the number of arguments passed to a function can be large. Consider the following case:

calculate(dataManager.getLastUpdate().getNumberOfChildren(),
               


        
6条回答
  •  庸人自扰
    2021-02-13 21:31

    I might assign the return values of the getNumberOf*() methods to variables:

    SomeObject lastUpdate = dataManager.getLastUpdate();
    int children = lastUpdate.getNumberOfChildren();
    int parents = lastUpdate.getNumberOfParents();
    int grandChildren = lastUpdate.getNumberOfGrandChildren();
    calculate(children, parents, grandChildren, milliseconds, somethingelse);
    

提交回复
热议问题